git ssb

1+

Daan Patchwork / patchwork



Tree: 455af00799601cb57c6ea54edad5e85c516b799f

Files: 455af00799601cb57c6ea54edad5e85c516b799f / lib / depject / profile / html / preview.js

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

Built with git-ssb-web