Files: e5ad753b8414d998113f9305e0826f4cf1035fe4 / plugs / message / html / meta / likes.js
1016 bytesRaw
1 | var nest = require('depnest') |
2 | var { h, computed, map, send } = require('mutant') |
3 | |
4 | var appRoot = require('app-root-path'); |
5 | var i18n = require(appRoot + '/lib/i18n').i18n |
6 | |
7 | exports.gives = nest('message.html.meta') |
8 | exports.needs = nest({ |
9 | 'message.obs.likes': 'first', |
10 | 'message.sheet.likes': 'first', |
11 | 'about.obs.name': 'first' |
12 | }) |
13 | |
14 | exports.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