git ssb

2+

mixmix / ticktack



Tree: 99dc6aa464a4c1cc228a6af744517def76da134f

Files: 99dc6aa464a4c1cc228a6af744517def76da134f / app / page / userShow.js

2396 bytesRaw
1const nest = require('depnest')
2const { h, computed, when } = require('mutant')
3
4exports.gives = nest('app.page.userShow')
5
6exports.needs = nest({
7 'app.html.link': 'first',
8 'app.html.nav': 'first',
9 'about.html.image': 'first',
10 'about.obs.name': 'first',
11 'contact.async.follow': 'first',
12 'contact.async.unfollow': 'first',
13 'contact.obs.followers': 'first',
14 'keys.sync.id': 'first',
15 'translations.sync.strings': 'first',
16})
17
18exports.create = (api) => {
19 return nest('app.page.userShow', userShow)
20
21 function userShow (location) {
22
23 const { feed } = location
24 const myId = api.keys.sync.id()
25
26 const strings = api.translations.sync.strings()
27
28 const { followers } = api.contact.obs
29
30 const youFollowThem = computed(followers(feed), followers => followers.has(myId))
31 const theyFollowYou = computed(followers(myId), followers => followers.has(feed))
32 const youAreFriends = computed([youFollowThem, theyFollowYou], (a, b) => a && b)
33
34 const ourRelationship = computed(
35 [youAreFriends, youFollowThem, theyFollowYou],
36 (youAreFriends, youFollowThem, theyFollowYou) => {
37 if (youAreFriends) return strings.userShow.state.friends
38 if (theyFollowYou) return strings.userShow.state.theyFollow
39 if (youFollowThem) return strings.userShow.state.youFollow
40 }
41 )
42 const { unfollow, follow } = api.contact.async
43 const followButton = when(followers(myId).sync,
44 when(youFollowThem,
45 h('Button -subtle', { 'ev-click': () => unfollow(feed) }, strings.userShow.action.unfollow),
46 h('Button -primary', { 'ev-click': () => follow(feed) }, strings.userShow.action.follow)
47 ),
48 h('Button', { disabled: 'disabled' }, strings.loading )
49 )
50
51 const Link = api.app.html.link
52
53 return h('Page -userShow', [
54 api.app.html.nav(),
55 h('h1', api.about.obs.name(feed)),
56 h('div.container', [
57 api.about.html.image(feed),
58 feed !== myId
59 ? h('div.friendship', [
60 h('div.state', ourRelationship),
61 followButton
62 ]) : '',
63 h('div', '...friends in common'),
64 h('div', '...groups dominic is in'),
65 feed !== myId
66 ? Link({ page: 'threadNew', feed }, h('Button -primary', strings.userShow.action.directMessage))
67 : '',
68 h('div', 'conversations you\'ve had with dominic'),
69 ])
70 ])
71 }
72}
73

Built with git-ssb-web