Files: 586cb11f23ec7cba4403726a638f35287118ae26 / plugs / message / html / meta / likes.js
1114 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 | 'sheet.profiles': '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: 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