Files: 159e6917c8854f4e90d61a60d2d82e6bd235b6e1 / modules / page / html / render / channels.js
1535 bytesRaw
1 | var nest = require('depnest') |
2 | var { h, send, when, computed, map } = require('mutant') |
3 | |
4 | exports.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 | |
14 | exports.gives = nest('page.html.render') |
15 | |
16 | exports.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 | ]) |
42 | }, {maxTime: 5, idle: true}) |
43 | ]) |
44 | ]) |
45 | |
46 | function subscribe (id) { |
47 | api.message.async.publish({ |
48 | type: 'channel', |
49 | channel: id, |
50 | subscribed: true |
51 | }) |
52 | } |
53 | |
54 | function unsubscribe (id) { |
55 | api.message.async.publish({ |
56 | type: 'channel', |
57 | channel: id, |
58 | subscribed: false |
59 | }) |
60 | } |
61 | }) |
62 | } |
63 |
Built with git-ssb-web