git ssb

2+

ev / mvd



Commit fd5b5ec859326033c364c31f5df00f867216815f

add labels to posts, render label views

Gwen Bell committed on 2/9/2019, 6:29:57 PM
Parent: 42c1864507578a06f12491c480992e258893497d

Files changed

render.jschanged
views.jschanged
render.jsView
@@ -30,8 +30,14 @@
3030 message.appendChild(tools.mini(msg, muted))
3131 return message
3232 }
3333
34 + else if (msg.value.content.type == 'label'){
35 + var content = h('span', ' labeled ', tools.messageLink(msg.value.content.link), ' as ', h('mark', h('a', {href: '/#label/' + msg.value.content.label}, msg.value.content.label)))
36 + message.appendChild(tools.mini(msg, content))
37 + return message
38 + }
39 +
3440 else if (msg.value.content.type == 'queue') {
3541 if (msg.value.content.queue == true) {
3642 var content = h('span', ' added ', tools.messageLink(msg.value.content.message), ' to their ', h('a', {href: '#queue'}, 'queue'))
3743 message.appendChild(tools.mini(msg, content))
@@ -259,8 +265,19 @@
259265 }
260266 })
261267 )
262268
269 + pull(
270 + sbot.query({query: [{$filter: {value: { content: {type: 'label', link: msg.key}}}}], limit: 100, live: true}),
271 + pull.drain(function (labels){
272 + console.log(labels)
273 + if (labels.value){
274 + message.appendChild(h('span', ' ', h('mark', h('a', {href: '/#label/' + labels.value.content.label}, labels.value.content.label))))
275 +
276 + }
277 + })
278 + )
279 +
263280 var name = avatar.name(msg.value.author)
264281
265282 var buttons = h('div.buttons')
266283
@@ -322,8 +339,35 @@
322339 message.replaceChild(compose, message.lastElementChild)
323340 }
324341 }))
325342
343 +
344 + var inputter = h('input', {placeholder: 'Add a label to this post ie art, books, new'})
345 +
346 + var labeler = h('div',
347 + inputter,
348 + h('button.btn', 'Publish label', {
349 + onclick: function () {
350 + var post = {}
351 + post.type = 'label',
352 + post.label = inputter.value,
353 + post.link = msg.key
354 +
355 + sbot.publish(post, function (err, msg){
356 + console.log(msg)
357 + labeler.parentNode.replaceChild(buttons, labeler)
358 + })
359 + }
360 + })
361 + )
362 +
363 + var labels = h('button.btn', 'Add label', {
364 + onclick: function () {
365 + buttons.parentNode.replaceChild(labeler, buttons)
366 + }
367 + })
368 +
369 + buttons.appendChild(labels)
326370 buttons.appendChild(tools.queueButton(msg))
327371 buttons.appendChild(tools.star(msg))
328372 message.appendChild(buttons)
329373 return message
views.jsView
@@ -35,8 +35,53 @@
3535
3636 screen.appendChild(hyperscroll(content))
3737 }
3838
39 +var labelStream = function (label){
40 + var content = h('div.content')
41 + var screen = document.getElementById('screen')
42 + screen.appendChild(hyperscroll(content))
43 + content.appendChild(h('div.breadcrumbs.message', h('a', {href: '/'}, 'label'), ' ⯈ ' , h('a', {href: '/#label/' + label}, label)))
44 + function createStream (opts) {
45 + return pull(
46 + Next(sbot.query, opts, ['value', 'timestamp']),
47 + pull.map(function (msg){
48 + if (msg.value) {
49 + sbot.get(msg.value.content.link, function (err, data) {
50 + if (data) {
51 + var message = {}
52 + message.value = data
53 + message.key = msg.value.content.link
54 + content.appendChild(render(message))
55 + }
56 + })
57 + }
58 + })
59 + )
60 + }
61 +
62 + pull(
63 + createStream({
64 + limit: 10,
65 + reverse: true,
66 + live: false,
67 + query: [{$filter: { value: { content: {type: 'label', label: label }, timestamp: { $gt: 0 }}}}]
68 + }),
69 + stream.bottom(content)
70 + )
71 +
72 + pull(
73 + createStream({
74 + limit: 10,
75 + old: false,
76 + live: true,
77 + query: [{$filter: { value: { content: {type: 'label', label: label }, timestamp: { $gt: 0 }}}}]
78 + }),
79 + stream.top(content)
80 + )
81 +}
82 +
83 +
3984 var privateStream = function () {
4085 var content = h('div.content')
4186 var screen = document.getElementById('screen')
4287 screen.appendChild(hyperscroll(content))
@@ -658,8 +703,10 @@
658703 } else if (ref.isFeed(src.substring(5))) {
659704 mentionsStream(src.substring(5))
660705 } else if (ref.isFeed(src.substring(8))) {
661706 friendsStream(src.substring(8))
707 + } else if (src.substring(0, 6) === 'label/') {
708 + labelStream(src.substring(6))
662709 } else if (src == 'queue') {
663710 queueStream()
664711 } else if (src == 'about') {
665712 about()

Built with git-ssb-web