git ssb

10+

Matt McKegg / patchwork



Tree: 5b9d7ca9bb4a61d94b54a1fc968703c840a856d9

Files: 5b9d7ca9bb4a61d94b54a1fc968703c840a856d9 / plugs / message / html / meta / likes.js

763 bytesRaw
1var nest = require('depnest')
2var { h, computed, map } = require('mutant')
3exports.gives = nest('message.html.meta')
4exports.needs = nest({
5 'message.obs.likes': 'first',
6 'about.obs.name': 'first'
7})
8
9exports.create = function (api) {
10 return nest('message.html.meta', function likes (msg) {
11 if (msg.key) {
12 return computed(api.message.obs.likes(msg.key), likeCount)
13 }
14 })
15
16 function likeCount (likes) {
17 if (likes.length) {
18 return [' ', h('span.likes', {
19 title: names(likes)
20 }, ['+', h('strong', `${likes.length}`)])]
21 }
22 }
23
24 function names (ids) {
25 var items = map(ids, api.about.obs.name)
26 return computed([items], (names) => {
27 return 'Liked by\n' + names.map((n) => `- ${n}`).join('\n')
28 })
29 }
30}
31

Built with git-ssb-web