git ssb

16+

Dominic / patchbay



Tree: 61db5f50ca3fff960bc1cf4f97b8066c664fd306

Files: 61db5f50ca3fff960bc1cf4f97b8066c664fd306 / app / page / channel.js

2187 bytesRaw
1const nest = require('depnest')
2const pull = require('pull-stream')
3const Scroller = require('pull-scroll')
4const { h, when } = require('mutant')
5
6exports.gives = nest('app.page.channel')
7
8exports.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
19exports.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({ meta: { type: 'post', channel: channelName } })
43 const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw)
44 const { container, content } = api.app.html.scroller({ prepend: [subscribeButton, composer, filterMenu] })
45
46 function draw () {
47 resetFeed({ container, content })
48
49 const openChannelSource = api.feed.pull.channel(channelName)
50
51 pull(
52 openChannelSource({old: false}),
53 filterUpThrough(),
54 Scroller(container, content, api.message.html.render, true, false)
55 )
56
57 pull(
58 openChannelSource({reverse: true}),
59 filterDownThrough(),
60 Scroller(container, content, api.message.html.render, false, false)
61 )
62 }
63 draw()
64
65 var page = h('Page -channel', {title: channel}, [
66 // filterMenu, // TODO - extract non-scroller els like filterMenu here
67 container
68 ])
69
70 // TODO better scroll hack for keyboard shortcuts
71 page.scroll = container.scroll
72
73 return page
74 }
75}
76

Built with git-ssb-web