Files: de181f394077c4a03e590b5325f9cb51c0ac27df / contact / html / follow.js
1397 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, Array: MutantArray, computed, when, map } = require('mutant') |
3 | |
4 | exports.gives = nest('contact.html.follow') |
5 | |
6 | exports.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 | |
14 | exports.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