git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 9e3d2a27287664a8a12ac78c22384a9748102890

Files: 9e3d2a27287664a8a12ac78c22384a9748102890 / plugs / message / html / meta / likes.js

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

Built with git-ssb-web