Files: 885b7de1caf8644fe426d6f49b82f1f738f9b3bf / app / page / channel.js
2207 bytesRaw
1 | const nest = require('depnest') |
2 | const pull = require('pull-stream') |
3 | const Scroller = require('pull-scroll') |
4 | const { h, when } = require('mutant') |
5 | |
6 | exports.gives = nest('app.page.channel') |
7 | |
8 | exports.needs = nest({ |
9 | 'app.html.filter': 'first', |
10 | 'app.html.scroller': 'first', |
11 | 'feed.pull.channel': 'first', |
12 | 'message.html.compose': 'first', |
13 | 'message.html.render': 'first', |
14 | 'channel.obs.subscribed': 'first', |
15 | 'keys.sync.id': 'first', |
16 | 'sbot.async.publish': 'first' |
17 | }) |
18 | |
19 | exports.create = function (api) { |
20 | return nest('app.page.channel', channelView) |
21 | |
22 | function channelView (location) { |
23 | const { channel } = location |
24 | |
25 | const channelName = channel.substr(1) |
26 | const myKey = api.keys.sync.id() |
27 | var subscribed = api.channel.obs.subscribed(myKey).has(channelName) |
28 | |
29 | function toggleSubscription () { |
30 | api.sbot.async.publish({ |
31 | type: 'channel', |
32 | channel: channelName, |
33 | subscribed: !subscribed() |
34 | }) |
35 | } |
36 | |
37 | const subscribeButton = h('button.-subscribe', |
38 | { 'ev-click': toggleSubscription }, |
39 | when(subscribed, 'Unsubscribe from channel', 'Subscribe to channel') |
40 | ) |
41 | |
42 | const composer = api.message.html.compose({ |
43 | location, |
44 | meta: { type: 'post', channel: channelName } }) |
45 | const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw) |
46 | const { container, content } = api.app.html.scroller({ prepend: [subscribeButton, composer, filterMenu] }) |
47 | |
48 | function draw () { |
49 | resetFeed({ container, content }) |
50 | |
51 | const openChannelSource = api.feed.pull.channel(channelName) |
52 | |
53 | pull( |
54 | openChannelSource({old: false}), |
55 | filterUpThrough(), |
56 | Scroller(container, content, api.message.html.render, true, false) |
57 | ) |
58 | |
59 | pull( |
60 | openChannelSource({reverse: true}), |
61 | filterDownThrough(), |
62 | Scroller(container, content, api.message.html.render, false, false) |
63 | ) |
64 | } |
65 | draw() |
66 | |
67 | var page = h('Page -channel', {title: channel}, [ |
68 | // filterMenu, // TODO - extract non-scroller els like filterMenu here |
69 | container |
70 | ]) |
71 | |
72 | // TODO better scroll hack for keyboard shortcuts |
73 | page.scroll = container.scroll |
74 | |
75 | return page |
76 | } |
77 | } |
78 |
Built with git-ssb-web