git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 5fb3695e2fdf7e69e3db206fd680def37464d8b6

Files: 5fb3695e2fdf7e69e3db206fd680def37464d8b6 / modules / page / html / render / channels.js

1878 bytesRaw
1var nest = require('depnest')
2var { h, send, when, computed, map } = require('mutant')
3
4exports.needs = nest({
5 'message.async.publish': 'first',
6 'keys.sync.id': 'first',
7 'channel.obs': {
8 subscribed: 'first',
9 recent: 'first'
10 },
11 'intl.sync.i18n': 'first'
12})
13
14exports.gives = nest('page.html.render')
15
16exports.create = function(api){
17 const i18n = api.intl.sync.i18n
18 return nest('page.html.render', function page(path){
19 if (path !== '/channels') return
20
21 var id = api.keys.sync.id()
22 var channels = api.channel.obs.recent()
23 var subscribedChannels = api.channel.obs.subscribed(id)
24 var loading = computed(subscribedChannels.sync, x => !x)
25
26 return h('div', { classList: 'Scroller'}, [
27 when(loading, [ h('Loading') ]),
28 h('div', {
29 classList: 'AllChannels',
30 hidden: loading
31 }, [
32 map(channels, (channel) => {
33 var subscribed = subscribedChannels.has(channel)
34 return h('a.channel', {
35 href: `#${channel}`,
36 classList: [
37 when(subscribed, '-subscribed')
38 ]
39 }, [
40 h('span.name', '#' + channel),
41 when(subscribed,
42 h('a.-unsubscribe', {
43 'ev-click': send(unsubscribe, channel)
44 }, i18n('Unsubscribe')),
45 h('a.-subscribe', {
46 'ev-click': send(subscribe, channel)
47 }, i18n('Subscribe'))
48 )
49 ])
50 }, {maxTime: 5, idle: true})
51 ])
52 ])
53
54
55 function subscribe (id) {
56 api.message.async.publish({
57 type: 'channel',
58 channel: id,
59 subscribed: true
60 })
61 }
62
63 function unsubscribe (id) {
64 api.message.async.publish({
65 type: 'channel',
66 channel: id,
67 subscribed: false
68 })
69 }
70 })
71}
72

Built with git-ssb-web