git ssb

2+

mixmix / ticktack



Commit 8cdccd655d04dc269300a1a05a44a64319b38607

nested comments implemented nice!

mix irving committed on 10/20/2017, 1:50:56 AM
Parent: 96a0fbf9d489182265e23a3452bd6ee7e963abbb

Files changed

app/html/comments.jschanged
app/html/comments.mcsschanged
app/html/comments.jsView
@@ -22,8 +22,19 @@
2222
2323 function comments (root) {
2424 const { messages, channel, lastId: branch } = api.feed.obs.thread(root)
2525
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+
2637 const meta = {
2738 type: 'post',
2839 root,
2940 branch,
@@ -33,16 +44,17 @@
3344 return messages.length > 5
3445 })
3546 const { compose } = api.message.html
3647
48+
3749 return h('Comments', [
3850 when(twoComposers, compose({ meta, shrink: true, canAttach: false })),
39- map(messages, msg => Comment(msg, branch)),
51+ map(messagesTree, msg => Comment(msg, root, branch)),
4052 compose({ meta, shrink: false, canAttach: false }),
4153 ])
4254 }
4355
44- function Comment (msgObs, branch) {
56+ function Comment (msgObs, root, branch) {
4557 const msg = resolve(msgObs)
4658
4759 const raw = get(msg, 'value.content.text')
4860 var className = api.unread.sync.isUnread(msg) ? ' -unread' : ' -read'
@@ -51,24 +63,25 @@
5163 if (!get(msg, 'value.content.root')) return
5264
5365 const { author, content } = msg.value
5466
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+ // })
6476
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({
6880 meta: {
6981 type: 'post',
70- root: msg.key,
82+ root,
83+ fork: msg.key,
7184 branch,
7285 channel: content.channel
7386 },
7487 shrink: false,
@@ -83,20 +96,20 @@
8396 h('div.name', api.about.obs.name(author)),
8497 api.message.html.timeago(msg)
8598 ]),
8699 h('section.content', api.message.html.markdown(raw)),
87- when(nestedReplies,
100+ when(msgObs.replies,
88101 h('section.replies',
89- map(nestedReplies, NestedComment)
102+ map(msgObs.replies, NestedComment)
90103 )
91104 ),
92105 h('section.actions', [
93106 h('div.reply', { 'ev-click': toggleCompose }, [
94107 h('i.fa.fa-commenting-o'),
95108 ]),
96109 api.message.html.likes(msg)
97110 ]),
98- when(composeOpen, composer),
111+ when(nestedReplyCompose, nestedReplyComposer),
99112 ])
100113 ])
101114 }
102115
@@ -121,4 +134,7 @@
121134 api.message.html.markdown(raw)
122135 }
123136 }
124137
138+function forkOf (msg) {
139+ return get(msg, 'value.content.fork')
140+}
app/html/comments.mcssView
@@ -73,9 +73,9 @@
7373 }
7474 }
7575
7676 Comment -nested {
77- padding: 1rem
77+ padding: 1rem 1rem 0 1rem
7878 $backgroundPrimaryText
7979 $roundTop
8080 $roundBottom
8181

Built with git-ssb-web