git ssb

2+

mixmix / ticktack



Tree: db07f3aa11263d691a9cda69238563a05b7c440e

Files: db07f3aa11263d691a9cda69238563a05b7c440e / contact / html / follow.js

1241 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 { unfollow, follow } = api.contact.async
28 const className = when(youFollowThem, '-following')
29
30 return h('Follow', { className },
31 when(theirFollowers.sync,
32 when(youFollowThem,
33 h('Button', { 'ev-click': () => unfollow(feed) }, strings.userShow.action.unfollow),
34 h('Button', { 'ev-click': () => follow(feed) }, strings.userShow.action.follow)
35 ),
36 h('Button', { disabled: 'disabled' }, strings.loading )
37 )
38 )
39 }
40}
41
42

Built with git-ssb-web