Files: 4e6ec20947fcc765efbf7a8e5947553f574943da / app / page / channelShow.js
2168 bytesRaw
1 | const nest = require('depnest') |
2 | const { h } = require('mutant') |
3 | const pull = require('pull-stream') |
4 | |
5 | exports.gives = nest('app.page.channelShow') |
6 | |
7 | exports.needs = nest({ |
8 | 'app.html.sideNav': 'first', |
9 | 'app.html.topNav': 'first', |
10 | 'app.html.scroller': 'first', |
11 | 'app.html.blogCard': 'first', |
12 | 'channel.html.subscribe': 'first', |
13 | 'feed.pull.channel': 'first', |
14 | 'history.sync.push': 'first', |
15 | 'translations.sync.strings': 'first' |
16 | }) |
17 | |
18 | exports.create = (api) => { |
19 | return nest('app.page.channelShow', channelShow) |
20 | |
21 | function channelShow (location) { |
22 | const strings = api.translations.sync.strings() |
23 | const { channel } = location |
24 | |
25 | createStream = api.feed.pull.channel(channel) |
26 | |
27 | const prepend = [ |
28 | api.app.html.topNav(location), |
29 | h('section.about', [ |
30 | h('h1', channel), |
31 | h('div.actions', [ |
32 | api.channel.html.subscribe(channel) |
33 | ]) |
34 | ]) |
35 | ] |
36 | |
37 | var channelPosts = api.app.html.scroller({ |
38 | classList: ['content'], |
39 | prepend, |
40 | stream: createStream, |
41 | filter: () => pull( |
42 | pull.filter(msg => { |
43 | const type = msg.value.content.type |
44 | return type === 'post' || type === 'blog' |
45 | }), |
46 | pull.filter(msg => !msg.value.content.root) // show only root messages |
47 | ), |
48 | // FUTURE : if we need better perf, we can add a persistent cache. At the moment this page is fast enough though. |
49 | // See implementation of app.html.sideNav for example |
50 | // store: recentMsgCache, |
51 | // updateTop: updateRecentMsgCache, |
52 | // updateBottom: updateRecentMsgCache, |
53 | render |
54 | }) |
55 | |
56 | location.page = location.page || 'channelShow' |
57 | // covers case where router.sync.normalise delivers a loc = { channel: '#channelName' } |
58 | // HACK: helps sideNav |
59 | |
60 | return h('Page -channelShow', { title: strings.home }, [ |
61 | api.app.html.sideNav(location), |
62 | channelPosts |
63 | ]) |
64 | } |
65 | |
66 | function render (blog) { |
67 | const { recps, channel } = blog.value.content |
68 | var onClick |
69 | if (channel && !recps) { onClick = (ev) => api.history.sync.push(Object.assign({}, blog, { page: 'blogShow' })) } |
70 | |
71 | return api.app.html.blogCard(blog, { onClick }) |
72 | } |
73 | } |
74 |
Built with git-ssb-web