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