git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 695f6649dd7fe33b57fc4b2bcbfc45d329100a1b

Files: 695f6649dd7fe33b57fc4b2bcbfc45d329100a1b / plugs / message / html / meta / likes.js

1114 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 'sheet.profiles': '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: nameList(i18n('Liked by'), likes),
24 href: '#',
25 'ev-click': send(displayLikes, likes)
26 }, [`${likes.length} ${likes.length === 1 ? i18n('like') : i18n('likes')}`])]
27 }
28 }
29
30 function nameList (prefix, ids) {
31 var items = map(ids, api.about.obs.name)
32 return computed([prefix, items], (prefix, names) => {
33 return (prefix ? (prefix + '\n') : '') + names.map((n) => `- ${n}`).join('\n')
34 })
35 }
36
37 function displayLikes (likes) {
38 api.sheet.profiles(likes, i18n('Liked by'))
39 }
40}
41

Built with git-ssb-web