git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 209cf6da3ac17a31133e9d4378d50f892a560a35

Files: 209cf6da3ac17a31133e9d4378d50f892a560a35 / plugs / message / html / meta / likes.js

763 bytesRaw
1var nest = require('depnest')
2var { h, computed, map } = require('mutant')
3exports.gives = nest('message.html.meta')
4exports.needs = nest({
5 'message.obs.likes': 'first',
6 'about.obs.name': 'first'
7})
8
9exports.create = function (api) {
10 return nest('message.html.meta', function likes (msg) {
11 if (msg.key) {
12 return computed(api.message.obs.likes(msg.key), likeCount)
13 }
14 })
15
16 function likeCount (likes) {
17 if (likes.length) {
18 return [' ', h('span.likes', {
19 title: names(likes)
20 }, ['+', h('strong', `${likes.length}`)])]
21 }
22 }
23
24 function names (ids) {
25 var items = map(ids, api.about.obs.name)
26 return computed([items], (names) => {
27 return 'Liked by\n' + names.map((n) => `- ${n}`).join('\n')
28 })
29 }
30}
31

Built with git-ssb-web