git ssb

1+

Daan Patchwork / patchwork



Tree: 58ab0241031aa549a35cce1e678c27065ae66221

Files: 58ab0241031aa549a35cce1e678c27065ae66221 / lib / depject / profile / html / preview.js

4246 bytesRaw
1const nest = require('depnest')
2const h = require('mutant/h')
3const map = require('mutant/map')
4const when = require('mutant/when')
5const computed = require('mutant/computed')
6const send = require('mutant/send')
7const { titleFromMarkdown } = require('../../../markdownSummary')
8
9exports.needs = nest({
10 'about.obs.name': 'first',
11 'about.obs.description': 'first',
12 'about.html.image': 'first',
13 'keys.sync.id': 'first',
14 'sheet.display': 'first',
15 'app.navigate': 'first',
16 'intl.sync.i18n': 'first',
17 'intl.sync.i18n_n': 'first',
18 'sheet.profiles': 'first',
19 'contact.html.followToggle': 'first',
20 'profile.obs.contact': 'first'
21})
22
23exports.gives = nest('profile.html.preview')
24
25exports.create = function (api) {
26 const i18n = api.intl.sync.i18n
27 const plural = api.intl.sync.i18n_n
28
29 return nest('profile.html.preview', function (id) {
30 const idLen = id.length
31 const name = api.about.obs.name(id)
32 const contact = api.profile.obs.contact(id)
33 const description = api.about.obs.description(id)
34
35 return h('ProfilePreview', [
36 h('header', [
37 h('div.image', api.about.html.image(id)),
38 h('div.main', [
39 h('div.title', [
40 h('h1', [
41 h('a', { href: '#', 'ev-click': () => api.app.navigate(id) }, [name])
42 ]),
43 h('div.meta', [
44 api.contact.html.followToggle(id, { block: false })
45 ])
46 ]),
47 h('section -publicKey', [
48 h('pre', { title: i18n('Public key for this profile') }, id)
49 ]),
50 h(
51 'section -profile', [
52 computed(description, (description) => {
53 const summary = titleFromMarkdown(description, idLen, 1)
54 return summary
55 })]
56 )
57 ])
58 ]),
59
60 when(contact.isYou, h('section -you', [
61 i18n('This is you.')
62 ])),
63
64 when(contact.notFollowing, [
65 when(contact.blockingFriendsCount,
66 h('section -blockWarning', [
67 h('a', {
68 href: '#',
69 'ev-click': send(displayBlockingFriends, contact.blockingFriends)
70 }, [
71 '⚠️ ', computed(['This person is blocked by %s of your friends.', contact.blockingFriendsCount], plural)
72 ])
73 ]),
74 when(contact.noOutgoing,
75 h('section -distanceWarning', [
76 '⚠️ ', i18n('This person does not follow anyone that follows you')
77 ]),
78 when(contact.noIncoming,
79 h('section -distanceWarning', [
80 '⚠️ ', i18n('You don\'t follow anyone who follows this person')
81 ]),
82 when(contact.mutualFriendsCount,
83 h('section -mutualFriends', [
84 h('a', {
85 href: '#',
86 title: nameList(i18n('Mutual Friends'), contact.mutualFriends),
87 'ev-click': send(displayMutualFriends, contact.mutualFriends)
88 }, [
89 '👥 ', computed(['You share %s mutual friends with this person.', contact.mutualFriendsCount], plural)
90 ])
91 ]),
92 h('section -mutualFriends', [
93 h('a', {
94 href: '#',
95 title: nameList(i18n('Followed by'), contact.incomingVia),
96 'ev-click': send(displayFollowedBy, contact.incomingVia)
97 }, [
98 '👥 ', computed(['You follow %s people that follow this person.', contact.incomingViaCount], plural)
99 ])
100 ])
101 )
102 )
103 )
104 )
105 ])
106 ])
107 })
108
109 function displayMutualFriends (profiles) {
110 api.sheet.profiles(profiles, i18n('Mutual Friends'))
111 }
112
113 function displayFollowedBy (profiles) {
114 api.sheet.profiles(profiles, i18n('Followed by'))
115 }
116
117 function displayBlockingFriends (profiles) {
118 api.sheet.profiles(profiles, i18n('Blocked by'))
119 }
120
121 function nameList (prefix, ids) {
122 const items = map(ids, api.about.obs.name)
123 return computed([prefix, items], (prefix, names) => {
124 return (prefix ? (prefix + '\n') : '') + names.map((n) => `- ${n}`).join('\n')
125 })
126 }
127}
128

Built with git-ssb-web