Files: e6df29b999257c928b0fe5316875680a479dba2e / message / html / commentsCount.js
827 bytesRaw
1 | var { h, computed, throttle, when } = require('mutant') |
2 | var nest = require('depnest') |
3 | |
4 | exports.needs = nest({ |
5 | 'keys.sync.id': 'first', |
6 | 'message.obs.likes': 'first' |
7 | }) |
8 | |
9 | exports.gives = nest('message.html.commentsCount') |
10 | |
11 | exports.create = (api) => { |
12 | return nest('message.html.commentsCount', function commentsCount (thread) { |
13 | var count = computed(throttle(thread.messages, 500), msgs => { |
14 | return msgs |
15 | .filter(msg => msg.value.content.root) // exclude root message / blog |
16 | .filter(msg => { |
17 | if (msg.value.content.type !== 'post') console.log(msg.value.content.type) |
18 | return msg.value.content.type === 'post' |
19 | }) |
20 | .length |
21 | }) |
22 | |
23 | return h('CommentsCount', [ |
24 | h('i.fa', { className: 'fa-commenting-o' }), |
25 | h('div.count', when(count, count)) |
26 | ]) |
27 | }) |
28 | } |
29 |
Built with git-ssb-web