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