git ssb

10+

Matt McKegg / patchwork



Tree: 63c02a8e459eeb0415408ada6ccd068308da3d5c

Files: 63c02a8e459eeb0415408ada6ccd068308da3d5c / modules / sheet / profiles.js

1851 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 'intl.sync.i18n': 'first'
14})
15
16exports.gives = nest('sheet.profiles')
17
18exports.create = function (api) {
19 const i18n = api.intl.sync.i18n
20 return nest('sheet.profiles', function (ids, title) {
21 api.sheet.display(close => {
22 var content = h('div', {
23 style: { padding: '20px' }
24 }, [
25 h('h2', {
26 style: { 'font-weight': 'normal' }
27 }, [title]),
28 renderContactBlock(ids)
29 ])
30
31 catchLinks(content, (href, external, anchor) => {
32 if (!external) {
33 api.app.navigate(href, anchor)
34 close()
35 }
36 })
37
38 return {
39 content,
40 footer: [
41 h('button -close', {
42 'ev-click': close
43 }, i18n('Close'))
44 ]
45 }
46 })
47 })
48
49 function renderContactBlock (profiles) {
50 var yourId = api.keys.sync.id()
51 var yourFollows = api.contact.obs.following(yourId)
52 profiles = api.profile.obs.rank(profiles)
53 return [
54 h('div', {
55 classList: 'ProfileList'
56 }, [
57 map(profiles, (id) => {
58 var following = computed(yourFollows, f => f.includes(id))
59 return h('a.profile', {
60 href: id,
61 classList: [
62 when(following, '-following')
63 ]
64 }, [
65 h('div.avatar', [api.about.html.image(id)]),
66 h('div.main', [
67 h('div.name', [ api.about.obs.name(id) ])
68 ])
69 ])
70 }, { idle: true })
71 ])
72 ]
73 }
74}
75

Built with git-ssb-web