git ssb

2+

mixmix / ticktack



Tree: 9f35971e4a97a20c215d6f58c35b2298f2411e96

Files: 9f35971e4a97a20c215d6f58c35b2298f2411e96 / app / page / blogIndex.js

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

Built with git-ssb-web