git ssb

2+

mixmix / ticktack



Commit c26a377b747816479b1dc93f160726ef84bf6205

show nested comments

mix irving committed on 10/19/2017, 3:33:20 AM
Parent: 19ff7d8be964bd96cd9f8ed89a1ed59c65197700

Files changed

app/html/comments.jschanged
app/html/comments.mcsschanged
app/page/blogShow.jschanged
app/page/error.jschanged
app/page/error.mcssadded
app/html/comments.jsView
@@ -6,10 +6,10 @@
66
77 exports.needs = nest({
88 'about.html.avatar': 'first',
99 'about.obs.name': 'first',
10+ 'backlinks.obs.for': 'first',
1011 'feed.obs.thread': 'first',
11- 'keys.sync.id': 'first',
1212 'message.html.markdown': 'first',
1313 'message.html.timeago': 'first',
1414 'message.html.likes': 'first',
1515 'unread.sync.markRead': 'first',
@@ -19,40 +19,78 @@
1919 exports.create = (api) => {
2020 return nest('app.html.comments', comments)
2121
2222 function comments (root) {
23- const myId = api.keys.sync.id()
24- const { messages } = api.feed.obs.thread(root)
23+ const thread = api.feed.obs.thread(root)
2524
2625 return h('Comments',
27- map(messages, Comment)
26+ map(thread.messages, Comment)
2827 )
2928
30- function Comment (msgObs) {
31- const msg = resolve(msgObs)
32- const raw = get(msg, 'value.content.text')
33- var className = api.unread.sync.isUnread(msg) ? ' -unread' : ' -read'
34- api.unread.sync.markRead(msg)
29+ }
3530
36- if (!get(msg, 'value.content.root')) return
31+ function Comment (msgObs) {
32+ const msg = resolve(msgObs)
3733
38- const { author } = msg.value
39- return h('Comment', { className }, [
40- h('div.left', api.about.html.avatar(author, 'tiny')),
41- h('div.right', [
42- h('section.context', [
43- h('div.name', api.about.obs.name(author)),
44- api.message.html.timeago(msg)
34+ const raw = get(msg, 'value.content.text')
35+ var className = api.unread.sync.isUnread(msg) ? ' -unread' : ' -read'
36+ api.unread.sync.markRead(msg)
37+
38+ if (!get(msg, 'value.content.root')) return
39+
40+ const { author } = msg.value
41+
42+ // TODO - move this upstream into patchcore:feed.obs.thread ??
43+ // OR change strategy to use forks
44+ const backlinks = api.backlinks.obs.for(msg.key)
45+ const nestedReplies = computed(backlinks, backlinks => {
46+ return backlinks.filter(backlinker => {
47+ const { type, root } = backlinker.value.content
48+ return type === 'post' && root === msg.key
49+ })
50+ })
51+
52+ return h('Comment', { className }, [
53+ h('div.left', api.about.html.avatar(author, 'tiny')),
54+ h('div.right', [
55+ h('section.context', [
56+ h('div.name', api.about.obs.name(author)),
57+ api.message.html.timeago(msg)
58+ ]),
59+ h('section.content', api.message.html.markdown(raw)),
60+ when(nestedReplies,
61+ h('section.replies',
62+ map(nestedReplies, NestedComment)
63+ )
64+ ),
65+ h('section.actions', [
66+ h('div.reply', [
67+ h('i.fa.fa-commenting-o'),
4568 ]),
46- h('section.content', api.message.html.markdown(raw)),
47- h('section.actions', [
48- h('div.reply', [
49- h('i.fa.fa-commenting-o'),
50- ]),
51- api.message.html.likes(msg)
52- ])
53- ])
69+ api.message.html.likes(msg)
70+ ]),
5471 ])
55- }
72+ ])
5673 }
74+
75+ function NestedComment (msgObs) {
76+ const msg = resolve(msgObs)
77+ const raw = get(msg, 'value.content.text')
78+ if (!raw) return
79+
80+ const { author } = msg.value
81+
82+ return h('Comment -nested', [
83+ h('div.left'),
84+ h('div.right', [
85+ h('section.context', [
86+ h('div.name', api.about.obs.name(author)),
87+ api.message.html.timeago(msg)
88+ ]),
89+ h('section.content', api.message.html.markdown(raw)),
90+ ])
91+ ])
92+
93+ api.message.html.markdown(raw)
94+ }
5795 }
5896
app/html/comments.mcssView
@@ -62,4 +62,20 @@
6262 }
6363 }
6464 }
6565
66+Comment -nested {
67+ padding: 1rem
68+ $backgroundPrimaryText
69+ $roundTop
70+ $roundBottom
71+
72+ margin-bottom: 1rem
73+
74+ div.left { margin: 0 }
75+ div.right {
76+ padding: 0
77+ border: 0
78+ margin: 0
79+ }
80+}
81+
app/page/blogShow.jsView
@@ -38,9 +38,8 @@
3838 channel: content.channel
3939 }
4040
4141 const { timeago, channel, markdown, compose } = api.message.html
42- const composer = compose({ meta, shrink: true })
4342
4443 return h('Page -blogShow', [
4544 api.app.html.context({ page: 'discover' }), // HACK to highlight discover
4645 h('div.content', [
@@ -59,10 +58,11 @@
5958 ])
6059 ]),
6160 h('div.break', h('hr')),
6261 h('section.blog', markdown(blog)),
63- composer,
62+ compose({ meta, shrink: true }),
6463 comments,
64+ compose({ meta, shrink: false })
6565 ]),
6666 ])
6767 }
6868 }
app/page/error.jsView
@@ -13,9 +13,9 @@
1313 return nest('app.page.error', error)
1414
1515 function error (location) {
1616 return h('Page -error', {title: strings.error}, [
17- strings.errorNotFound,
17+ h('div.message', strings.errorNotFound),
1818 h('pre', [JSON.stringify(location, null, 2)])
1919 ])
2020 }
2121 }
app/page/error.mcssView
@@ -1,0 +1,6 @@
1+Page -error {
2+ padding: 1rem
3+
4+ flex-direction: column
5+}
6+

Built with git-ssb-web