git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 5fb3695e2fdf7e69e3db206fd680def37464d8b6

Files: 5fb3695e2fdf7e69e3db206fd680def37464d8b6 / 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