Commit fd5b5ec859326033c364c31f5df00f867216815f
add labels to posts, render label views
Gwen Bell committed on 2/9/2019, 6:29:57 PMParent: 42c1864507578a06f12491c480992e258893497d
Files changed
render.js | changed |
views.js | changed |
render.js | ||
---|---|---|
@@ -30,8 +30,14 @@ | ||
30 | 30 … | message.appendChild(tools.mini(msg, muted)) |
31 | 31 … | return message |
32 | 32 … | } |
33 | 33 … | |
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 … | + | |
34 | 40 … | else if (msg.value.content.type == 'queue') { |
35 | 41 … | if (msg.value.content.queue == true) { |
36 | 42 … | var content = h('span', ' added ', tools.messageLink(msg.value.content.message), ' to their ', h('a', {href: '#queue'}, 'queue')) |
37 | 43 … | message.appendChild(tools.mini(msg, content)) |
@@ -259,8 +265,19 @@ | ||
259 | 265 … | } |
260 | 266 … | }) |
261 | 267 … | ) |
262 | 268 … | |
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 … | + | |
263 | 280 … | var name = avatar.name(msg.value.author) |
264 | 281 … | |
265 | 282 … | var buttons = h('div.buttons') |
266 | 283 … | |
@@ -322,8 +339,35 @@ | ||
322 | 339 … | message.replaceChild(compose, message.lastElementChild) |
323 | 340 … | } |
324 | 341 … | })) |
325 | 342 … | |
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) | |
326 | 370 … | buttons.appendChild(tools.queueButton(msg)) |
327 | 371 … | buttons.appendChild(tools.star(msg)) |
328 | 372 … | message.appendChild(buttons) |
329 | 373 … | return message |
views.js | ||
---|---|---|
@@ -35,8 +35,53 @@ | ||
35 | 35 … | |
36 | 36 … | screen.appendChild(hyperscroll(content)) |
37 | 37 … | } |
38 | 38 … | |
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 … | + | |
39 | 84 … | var privateStream = function () { |
40 | 85 … | var content = h('div.content') |
41 | 86 … | var screen = document.getElementById('screen') |
42 | 87 … | screen.appendChild(hyperscroll(content)) |
@@ -658,8 +703,10 @@ | ||
658 | 703 … | } else if (ref.isFeed(src.substring(5))) { |
659 | 704 … | mentionsStream(src.substring(5)) |
660 | 705 … | } else if (ref.isFeed(src.substring(8))) { |
661 | 706 … | friendsStream(src.substring(8)) |
707 … | + } else if (src.substring(0, 6) === 'label/') { | |
708 … | + labelStream(src.substring(6)) | |
662 | 709 … | } else if (src == 'queue') { |
663 | 710 … | queueStream() |
664 | 711 … | } else if (src == 'about') { |
665 | 712 … | about() |
Built with git-ssb-web