Files: b6939f54fe19996c6c2471370cead05c07910c52 / modules / page / html / render / channels.js
1846 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 | 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 | function subscribe (id) { |
55 | api.message.async.publish({ |
56 | type: 'channel', |
57 | channel: id, |
58 | subscribed: true |
59 | }) |
60 | } |
61 | |
62 | function unsubscribe (id) { |
63 | api.message.async.publish({ |
64 | type: 'channel', |
65 | channel: id, |
66 | subscribed: false |
67 | }) |
68 | } |
69 | }) |
70 | } |
71 |
Built with git-ssb-web