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