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