Files: 7ceec7443b73d5a618748aaefea62cbfa9b909b7 / plugs / message / html / meta / likes.js
983 bytesRaw
1 | var nest = require('depnest') |
2 | var { h, computed, map, send } = require('mutant') |
3 | |
4 | exports.gives = nest('message.html.meta') |
5 | exports.needs = nest({ |
6 | 'message.obs.likes': 'first', |
7 | 'message.sheet.likes': 'first', |
8 | 'about.obs.name': 'first', |
9 | 'intl.sync.i18n': 'first', |
10 | }) |
11 | |
12 | exports.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