git ssb

2+

mixmix / ticktack



Tree: adca29179dee2177af6fefa725c91581ffef5395

Files: adca29179dee2177af6fefa725c91581ffef5395 / channel / html / subscribe.js

942 bytesRaw
1const nest = require('depnest')
2const { h, when } = require('mutant')
3
4exports.gives = nest('channel.html.subscribe')
5
6exports.needs = nest({
7 'translations.sync.strings': 'first',
8 'channel.obs.isSubscribedTo': 'first',
9 'channel.async.subscribe': 'first',
10 'channel.async.unsubscribe': 'first'
11})
12
13exports.create = function (api) {
14 return nest('channel.html.subscribe', (channel) => {
15 channel = channel.replace(/^#/, '')
16 const strings = api.translations.sync.strings()
17 const { subscribe, unsubscribe } = api.channel.async
18 const isSubscribed = api.channel.obs.isSubscribedTo(channel)
19
20 isSubscribed(val => {
21 console.log(channel, 'subscribed:', val)
22 })
23
24 return when(isSubscribed,
25 h('Button', { 'ev-click': () => unsubscribe(channel) }, strings.channelShow.action.unsubscribe),
26 h('Button -primary', { 'ev-click': () => subscribe(channel) }, strings.channelShow.action.subscribe)
27 )
28 })
29}
30

Built with git-ssb-web