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