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