git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: d4131d5fd9230e7811031665045b96e6b8c6eb1d

Files: d4131d5fd9230e7811031665045b96e6b8c6eb1d / modules / message / sheet / likes.js

1772 bytesRaw
1var {h, when, map, computed} = require('mutant')
2var nest = require('depnest')
3var catchLinks = require('../../../lib/catch-links')
4
5exports.needs = nest({
6 'sheet.display': 'first',
7 'keys.sync.id': 'first',
8 'contact.obs.following': 'first',
9 'profile.obs.rank': 'first',
10 'about.html.image': 'first',
11 'about.obs.name': 'first',
12 'app.navigate': 'first'
13})
14
15exports.gives = nest('message.sheet.likes')
16
17exports.create = function (api) {
18 return nest('message.sheet.likes', function (ids) {
19 api.sheet.display(close => {
20 var content = h('div', {
21 style: { padding: '20px' }
22 }, [
23 h('h2', {
24 style: { 'font-weight': 'normal' }
25 }, ['Liked by']),
26 renderContactBlock(ids)
27 ])
28
29 catchLinks(content, (href, external) => {
30 if (!external) {
31 api.app.navigate(href)
32 close()
33 }
34 })
35
36 return {
37 content,
38 footer: [
39 h('button -close', {
40 'ev-click': close
41 }, 'Close')
42 ]
43 }
44 })
45 })
46
47 function renderContactBlock (profiles) {
48 var yourId = api.keys.sync.id()
49 var yourFollows = api.contact.obs.following(yourId)
50 profiles = api.profile.obs.rank(profiles)
51 return [
52 h('div', {
53 classList: 'ProfileList'
54 }, [
55 map(profiles, (id) => {
56 var following = computed(yourFollows, f => f.has(id))
57 return h('a.profile', {
58 href: id,
59 classList: [
60 when(following, '-following')
61 ]
62 }, [
63 h('div.avatar', [api.about.html.image(id)]),
64 h('div.main', [
65 h('div.name', [ api.about.obs.name(id) ])
66 ])
67 ])
68 }, { idle: true })
69 ])
70 ]
71 }
72}
73

Built with git-ssb-web