Files: b10ce2e3fb81fd4e7ded0080858d4a7ff1d508f9 / app / html / comments.js
1621 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, Array: MutantArray, map, computed, when, resolve } = require('mutant') |
3 | const get = require('lodash/get') |
4 | |
5 | exports.gives = nest('app.html.comments') |
6 | |
7 | exports.needs = nest({ |
8 | 'about.html.avatar': 'first', |
9 | 'about.obs.name': 'first', |
10 | 'feed.obs.thread': 'first', |
11 | 'keys.sync.id': 'first', |
12 | 'message.html.markdown': 'first', |
13 | 'message.html.timeago': 'first', |
14 | 'message.html.likes': 'first', |
15 | 'unread.sync.markRead': 'first', |
16 | 'unread.sync.isUnread': 'first', |
17 | }) |
18 | |
19 | exports.create = (api) => { |
20 | return nest('app.html.comments', comments) |
21 | |
22 | function comments (root) { |
23 | const myId = api.keys.sync.id() |
24 | const { messages } = api.feed.obs.thread(root) |
25 | |
26 | return h('Comments', |
27 | map(messages, Comment) |
28 | ) |
29 | |
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) |
35 | |
36 | if (!get(msg, 'value.content.root')) return |
37 | |
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) |
45 | ]), |
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 | ]) |
54 | ]) |
55 | } |
56 | } |
57 | } |
58 | |
59 |
Built with git-ssb-web