git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: a97b2ac07374b443c84bbd1f8d2c42f40456a4bb

Files: a97b2ac07374b443c84bbd1f8d2c42f40456a4bb / modules / profile / html / preview.js

3373 bytesRaw
1var nest = require('depnest')
2var h = require('mutant/h')
3var computed = require('mutant/computed')
4var send = require('mutant/send')
5
6exports.needs = nest({
7 'about.obs': {
8 name: 'first',
9 description: 'first',
10 names: 'first',
11 images: 'first',
12 color: 'first'
13 },
14 'blob.sync.url': 'first',
15 'blob.html.input': 'first',
16 'message.html.markdown': 'first',
17 'about.html.image': 'first',
18 'keys.sync.id': 'first',
19 'sheet.display': 'first',
20 'profile.obs.rank': 'first',
21 'app.navigate': 'first',
22 'contact.obs': {
23 followers: 'first',
24 following: 'first',
25 blockers: 'first'
26 },
27 'contact.async.block': 'first',
28 'contact.async.unblock': 'first',
29 'intl.sync.i18n': 'first',
30 'intl.sync.i18n_n': 'first',
31 'profile.obs.hops': 'first',
32 'sheet.profiles': 'first',
33 'contact.html.followToggle': 'first'
34})
35
36exports.gives = nest('profile.html.preview')
37
38exports.create = function (api) {
39 const i18n = api.intl.sync.i18n
40 const plural = api.intl.sync.i18n_n
41
42 return nest('profile.html.preview', function (id) {
43 var name = api.about.obs.name(id)
44 var description = api.about.obs.description(id)
45 var yourId = api.keys.sync.id()
46 var yourFollows = api.contact.obs.following(yourId)
47 var yourFollowers = api.contact.obs.followers(yourId)
48
49 var rawFollowers = api.contact.obs.followers(id)
50 var rawFollowing = api.contact.obs.following(id)
51 var hops = api.profile.obs.hops(yourId, id)
52
53 var mutualFriends = computed([yourFollowers, yourFollows, rawFollowers, rawFollowing], (first, ...rest) => {
54 return first.filter(value => rest.every((collection) => collection.includes(value)))
55 })
56
57 return h('ProfilePreview', [
58 h('header', [
59 h('div.image', api.about.html.image(id)),
60 h('div.main', [
61 h('div.title', [
62 h('h1', [
63 h('a', {href: id, 'ev-click': () => api.app.navigate(id)}, [name])
64 ]),
65 h('div.meta', [
66 api.contact.html.followToggle(id, {block: false})
67 ])
68 ]),
69 h('section -publicKey', [
70 h('pre', {title: i18n('Public key for this profile')}, id)
71 ])
72 ])
73 ]),
74 computed(hops, (value) => {
75 if (value) {
76 if (value[0] > 2 || value[1] === undefined) {
77 return h('section -distanceWarning', [
78 '⚠️ ', i18n(`You don't follow anyone who follows this person`)
79 ])
80 } else if (value[1] > 2 || value[1] === undefined) {
81 return h('section -distanceWarning', [
82 '⚠️ ', i18n('This person does not follow anyone that follows you')
83 ])
84 } else if (value[0] === 2) {
85 return h('section -mutualFriends', [
86 h('a', {
87 href: '#',
88 'ev-click': send(displayMutualFriends, mutualFriends)
89 }, [
90 computed(mutualFriends, (items) => {
91 return plural('You share %s mutual friends with this person.', items.length)
92 })
93 ])
94 ])
95 } else if (value[0] === 0) {
96 return h('section', [
97 i18n('This is you.')
98 ])
99 }
100 }
101 })
102 ])
103 })
104
105 function displayMutualFriends (profiles) {
106 api.sheet.profiles(profiles, i18n('Mutual Friends'))
107 }
108}
109

Built with git-ssb-web