Commit 8cdccd655d04dc269300a1a05a44a64319b38607
nested comments implemented nice!
mix irving committed on 10/20/2017, 1:50:56 AMParent: 96a0fbf9d489182265e23a3452bd6ee7e963abbb
Files changed
app/html/comments.js | changed |
app/html/comments.mcss | changed |
app/html/comments.js | ||
---|---|---|
@@ -22,8 +22,19 @@ | ||
22 | 22 | |
23 | 23 | function comments (root) { |
24 | 24 | const { messages, channel, lastId: branch } = api.feed.obs.thread(root) |
25 | 25 | |
26 | + // TODO - move this up into Patchcore | |
27 | + const messagesTree = computed(messages, msgs => { | |
28 | + return msgs | |
29 | + .filter(msg => forkOf(msg) === undefined) | |
30 | + .map(threadMsg => { | |
31 | + const nestedReplies = msgs.filter(msg => forkOf(msg) === threadMsg.key) | |
32 | + threadMsg.replies = nestedReplies | |
33 | + return threadMsg | |
34 | + }) | |
35 | + }) | |
36 | + | |
26 | 37 | const meta = { |
27 | 38 | type: 'post', |
28 | 39 | root, |
29 | 40 | branch, |
@@ -33,16 +44,17 @@ | ||
33 | 44 | return messages.length > 5 |
34 | 45 | }) |
35 | 46 | const { compose } = api.message.html |
36 | 47 | |
48 | + | |
37 | 49 | return h('Comments', [ |
38 | 50 | when(twoComposers, compose({ meta, shrink: true, canAttach: false })), |
39 | - map(messages, msg => Comment(msg, branch)), | |
51 | + map(messagesTree, msg => Comment(msg, root, branch)), | |
40 | 52 | compose({ meta, shrink: false, canAttach: false }), |
41 | 53 | ]) |
42 | 54 | } |
43 | 55 | |
44 | - function Comment (msgObs, branch) { | |
56 | + function Comment (msgObs, root, branch) { | |
45 | 57 | const msg = resolve(msgObs) |
46 | 58 | |
47 | 59 | const raw = get(msg, 'value.content.text') |
48 | 60 | var className = api.unread.sync.isUnread(msg) ? ' -unread' : ' -read' |
@@ -51,24 +63,25 @@ | ||
51 | 63 | if (!get(msg, 'value.content.root')) return |
52 | 64 | |
53 | 65 | const { author, content } = msg.value |
54 | 66 | |
55 | - // TODO - move this upstream into patchcore:feed.obs.thread ?? | |
56 | - // OR change strategy to use forks | |
57 | - const backlinks = api.backlinks.obs.for(msg.key) | |
58 | - const nestedReplies = computed(backlinks, backlinks => { | |
59 | - return backlinks.filter(backlinker => { | |
60 | - const { type, root } = backlinker.value.content | |
61 | - return type === 'post' && root === msg.key | |
62 | - }) | |
63 | - }) | |
67 | + // // TODO - move this upstream into patchcore:feed.obs.thread ?? | |
68 | + // // OR change strategy to use forks | |
69 | + // const backlinks = api.backlinks.obs.for(msg.key) | |
70 | + // const nestedReplies = computed(backlinks, backlinks => { | |
71 | + // return backlinks.filter(backlinker => { | |
72 | + // const { type, root } = backlinker.value.content | |
73 | + // return type === 'post' && root === msg.key | |
74 | + // }) | |
75 | + // }) | |
64 | 76 | |
65 | - var composeOpen = Value(false) | |
66 | - const toggleCompose = () => composeOpen.set(!composeOpen()) | |
67 | - const composer = api.message.html.compose({ | |
77 | + var nestedReplyCompose = Value(false) | |
78 | + const toggleCompose = () => nestedReplyCompose.set(!nestedReplyCompose()) | |
79 | + const nestedReplyComposer = api.message.html.compose({ | |
68 | 80 | meta: { |
69 | 81 | type: 'post', |
70 | - root: msg.key, | |
82 | + root, | |
83 | + fork: msg.key, | |
71 | 84 | branch, |
72 | 85 | channel: content.channel |
73 | 86 | }, |
74 | 87 | shrink: false, |
@@ -83,20 +96,20 @@ | ||
83 | 96 | h('div.name', api.about.obs.name(author)), |
84 | 97 | api.message.html.timeago(msg) |
85 | 98 | ]), |
86 | 99 | h('section.content', api.message.html.markdown(raw)), |
87 | - when(nestedReplies, | |
100 | + when(msgObs.replies, | |
88 | 101 | h('section.replies', |
89 | - map(nestedReplies, NestedComment) | |
102 | + map(msgObs.replies, NestedComment) | |
90 | 103 | ) |
91 | 104 | ), |
92 | 105 | h('section.actions', [ |
93 | 106 | h('div.reply', { 'ev-click': toggleCompose }, [ |
94 | 107 | h('i.fa.fa-commenting-o'), |
95 | 108 | ]), |
96 | 109 | api.message.html.likes(msg) |
97 | 110 | ]), |
98 | - when(composeOpen, composer), | |
111 | + when(nestedReplyCompose, nestedReplyComposer), | |
99 | 112 | ]) |
100 | 113 | ]) |
101 | 114 | } |
102 | 115 | |
@@ -121,4 +134,7 @@ | ||
121 | 134 | api.message.html.markdown(raw) |
122 | 135 | } |
123 | 136 | } |
124 | 137 | |
138 | +function forkOf (msg) { | |
139 | + return get(msg, 'value.content.fork') | |
140 | +} |
Built with git-ssb-web