git ssb

10+

Matt McKegg / patchwork



Tree: b70759f872a7c4a5c73cc3413f10d221633d860c

Files: b70759f872a7c4a5c73cc3413f10d221633d860c / modules / page / html / render / channels.js

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

Built with git-ssb-web