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