Commit 47416e4ca950ed7de91562f1c6ede9486e4aa6d9
add message/thread view
Matt McKegg committed on 2/15/2017, 12:20:30 PMParent: 03d17cff841c2fed3e864e0b507f5e8045e4a356
Files changed
modules/feed/html/thread.js | added |
modules/page/html/render/message.js | added |
plugs/message/html/layout/default.js | changed |
styles/feed-event.mcss | changed |
styles/message.mcss | changed |
styles/thread.mcss | added |
modules/feed/html/thread.js | ||
---|---|---|
@@ -1,0 +1,26 @@ | ||
1 | +var { h, computed, map } = require('mutant') | |
2 | +var nest = require('depnest') | |
3 | + | |
4 | +exports.needs = nest({ | |
5 | + 'feed.obs.thread': 'first', | |
6 | + 'message.html.render': 'first' | |
7 | +}) | |
8 | + | |
9 | +exports.gives = nest('feed.html.thread') | |
10 | + | |
11 | +exports.create = function (api) { | |
12 | + return nest('feed.html.thread', function (rootId) { | |
13 | + var thread = api.feed.obs.thread(rootId) | |
14 | + | |
15 | + var container = h('div', {className: 'Thread'}, [ | |
16 | + map(thread.messages, (msg) => { | |
17 | + return computed([msg, thread.previousKey(msg)], (msg, previousId) => { | |
18 | + return api.message.html.render(msg, {previousId}) | |
19 | + }) | |
20 | + }) | |
21 | + ]) | |
22 | + | |
23 | + container.sync = thread.sync | |
24 | + return container | |
25 | + }) | |
26 | +} |
modules/page/html/render/message.js | ||
---|---|---|
@@ -1,0 +1,40 @@ | ||
1 | +var { h, when, send, Value, Proxy, watch } = require('mutant') | |
2 | +var pull = require('pull-stream') | |
3 | +var nest = require('depnest') | |
4 | +var ref = require('ssb-ref') | |
5 | + | |
6 | +exports.needs = nest({ | |
7 | + 'keys.sync.id': 'first', | |
8 | + 'feed.html.thread': 'first', | |
9 | + 'message.html.render': 'first', | |
10 | + 'sbot.async.get': 'first' | |
11 | +}) | |
12 | + | |
13 | +exports.gives = nest('page.html.render') | |
14 | + | |
15 | +exports.create = function (api) { | |
16 | + return nest('page.html.render', function channel (id) { | |
17 | + if (!ref.isMsg(id)) return | |
18 | + var loader = h('div', {className: 'Loading -large'}) | |
19 | + var result = Proxy(loader) | |
20 | + | |
21 | + api.sbot.async.get(id, (err, value) => { | |
22 | + if (err) return result.set(h('div', {className: 'Error'}, ['Cannot load thead'])) | |
23 | + if (value.content.root) { | |
24 | + result.set(h('div', {className: 'FeedEvent'}, [ | |
25 | + h('a.full', {href: value.content.root}, ['View full thread']), | |
26 | + h('div.replies', [ | |
27 | + api.message.html.render({key: id, value}) | |
28 | + ]) | |
29 | + ])) | |
30 | + } else { | |
31 | + var thread = api.feed.html.thread(id) | |
32 | + result.set(when(thread.sync, thread, loader)) | |
33 | + } | |
34 | + }) | |
35 | + | |
36 | + return h('div', {className: 'SplitView'}, [ | |
37 | + h('div.main', result) | |
38 | + ]) | |
39 | + }) | |
40 | +} |
plugs/message/html/layout/default.js | ||
---|---|---|
@@ -24,12 +24,13 @@ | ||
24 | 24 | var replyInfo = null |
25 | 25 | |
26 | 26 | if (msg.value.content.root) { |
27 | 27 | classList.push('-reply') |
28 | - if (!opts.previousId) { | |
29 | - replyInfo = h('span', ['in reply to ', api.message.html.link(msg.value.content.root)]) | |
30 | - } else if (opts.previousId && last(msg.value.content.branch) && opts.previousId !== last(msg.value.content.branch)) { | |
31 | - replyInfo = h('span', ['in reply to ', api.message.html.link(last(msg.value.content.branch))]) | |
28 | + var branch = msg.value.content.branch | |
29 | + if (branch) { | |
30 | + if (!opts.previousId || (opts.previousId && last(branch) && opts.previousId !== last(branch))) { | |
31 | + replyInfo = h('span', ['in reply to ', api.message.html.link(last(branch))]) | |
32 | + } | |
32 | 33 | } |
33 | 34 | } |
34 | 35 | |
35 | 36 | return h('div', { |
styles/feed-event.mcss | ||
---|---|---|
@@ -1,7 +1,6 @@ | ||
1 | 1 | FeedEvent { |
2 | 2 | display: flex |
3 | - flex: 1 | |
4 | 3 | flex-direction: column |
5 | 4 | background: white |
6 | 5 | max-width: 700px |
7 | 6 | margin: 10px auto |
Built with git-ssb-web