git ssb

10+

Matt McKegg / patchwork



Tree: f98587b805da63c46cc6810f870c08e333ff5f4d

Files: f98587b805da63c46cc6810f870c08e333ff5f4d / plugs / message / html / meta / likes.js

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

Built with git-ssb-web