Files: 5408d3118894220a8d70afa1754390b36514ba45 / app / page / channel.js
2313 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, render, true, false) |
57 | ) |
58 | |
59 | pull( |
60 | openChannelSource({ reverse: true }), |
61 | filterDownThrough(), |
62 | Scroller(container, content, render, false, false) |
63 | ) |
64 | } |
65 | draw() |
66 | |
67 | // TODO rollups |
68 | function render (msg) { |
69 | return api.message.html.render(msg, { showTitle: true }) |
70 | } |
71 | |
72 | var page = h('Page -channel', { title: channel }, [ |
73 | // filterMenu, // TODO - extract non-scroller els like filterMenu here |
74 | container |
75 | ]) |
76 | |
77 | // TODO better scroll hack for keyboard shortcuts |
78 | page.keyboardScroll = container.keyboardScroll |
79 | |
80 | return page |
81 | } |
82 | } |
83 |
Built with git-ssb-web