git ssb

2+

mixmix / ticktack



Tree: fc257fd3b75785431205902b7f48764d220ef8ca

Files: fc257fd3b75785431205902b7f48764d220ef8ca / 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