Files: 4a58e38afe8d7cd5659d286607457aeb91ee7638 / contact / html / follow.js
1241 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 { 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