git ssb

2+

mixmix / ticktack



Tree: 26d61ca780b49f14cec3dc071c03f71b4b3da905

Files: 26d61ca780b49f14cec3dc071c03f71b4b3da905 / contact / html / follow.js

1397 bytesRaw
1const nest = require('depnest')
2const { h, Array: MutantArray, computed, when, map } = require('mutant')
3
4exports.gives = nest('contact.html.follow')
5
6exports.needs = nest({
7 'contact.async.follow': 'first',
8 'contact.async.unfollow': 'first',
9 'contact.obs.followers': 'first',
10 'keys.sync.id': 'first',
11 'translations.sync.strings': 'first'
12})
13
14exports.create = (api) => {
15 return nest('contact.html.follow', follow)
16
17 function follow (feed) {
18 const strings = api.translations.sync.strings()
19 const myId = api.keys.sync.id()
20
21 if (feed === myId) return
22
23 const { followers } = api.contact.obs
24 const theirFollowers = followers(feed)
25 const youFollowThem = computed(theirFollowers, followers => followers.includes(myId))
26
27 const className = when(youFollowThem, '-following')
28 const follow = (feed) => ev => {
29 ev.stopPropagation()
30 api.contact.async.follow(feed)
31 }
32 const unfollow = (feed) => ev => {
33 ev.stopPropagation()
34 api.contact.async.unfollow(feed)
35 }
36
37 return h('Follow', { className },
38 when(theirFollowers.sync,
39 when(youFollowThem,
40 h('Button', { 'ev-click': unfollow(feed) }, strings.userShow.action.unfollow),
41 h('Button -strong', { 'ev-click': follow(feed) }, strings.userShow.action.follow)
42 ),
43 h('Button', { disabled: 'disabled' }, strings.loading)
44 )
45 )
46 }
47}
48

Built with git-ssb-web