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