Files: b3fdce7b121819753c77c856de809a9b91b884b5 / app / page / channelShow.js
3057 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 | let cb = () => { |
36 | youSubscribe.set(isSubscribedTo(location.channel, myId)) |
37 | } |
38 | |
39 | var searchVal = resolve(location.channel) |
40 | var searchResults = computed([api.channel.obs.recent(), searchVal], (channels, val) => { |
41 | if (val.length < 2) return [] |
42 | |
43 | return channels.filter(c => c.toLowerCase().indexOf(val.toLowerCase()) > -1) |
44 | }) |
45 | |
46 | |
47 | |
48 | createStream = api.feed.pull.channel(location.channel) |
49 | |
50 | |
51 | const prepend = [ |
52 | api.app.html.topNav(location), |
53 | h('section.about', [ |
54 | h('h1', location.channel), |
55 | h('div.actions', [ |
56 | when(youSubscribe, |
57 | h('Button', { 'ev-click': () => subscribe(location.channel, cb) }, strings.channelShow.action.unsubscribe), |
58 | h('Button', { 'ev-click': () => unsubscribe(location.channel, cb) }, strings.channelShow.action.subscribe) |
59 | ) |
60 | ]) |
61 | ]), |
62 | ] |
63 | |
64 | var channelPosts = api.app.html.scroller({ |
65 | classList: ['content'], |
66 | prepend, |
67 | stream: createStream, |
68 | filter: () => pull( |
69 | pull.filter(msg => { |
70 | const type = msg.value.content.type |
71 | return type === 'post' || type === 'blog' |
72 | }), |
73 | pull.filter(msg => !msg.value.content.root) // show only root messages |
74 | ), |
75 | // FUTURE : if we need better perf, we can add a persistent cache. At the moment this page is fast enough though. |
76 | // See implementation of app.html.sideNav for example |
77 | // store: recentMsgCache, |
78 | // updateTop: updateRecentMsgCache, |
79 | // updateBottom: updateRecentMsgCache, |
80 | render |
81 | }) |
82 | |
83 | return h('Page -channelShow', { title: strings.home }, [ |
84 | api.app.html.sideNav(location), |
85 | channelPosts |
86 | ]) |
87 | } |
88 | |
89 | |
90 | function render(blog) { |
91 | const { recps, channel } = blog.value.content |
92 | var onClick |
93 | if (channel && !recps) |
94 | onClick = (ev) => api.history.sync.push(Object.assign({}, blog, { page: 'blogShow' })) |
95 | |
96 | return api.app.html.blogCard(blog, { onClick }) |
97 | } |
98 | } |
99 | |
100 | |
101 |
Built with git-ssb-web