git ssb

10+

Matt McKegg / patchwork



Tree: 1a1dfa987b784a002e626f97e18aeaf2164d1299

Files: 1a1dfa987b784a002e626f97e18aeaf2164d1299 / plugs / message / html / meta / likes.js

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

Built with git-ssb-web