git ssb

2+

mixmix / ticktack



Tree: 52acefb26cfdc545a5bef98c649d3cfbec4ac257

Files: 52acefb26cfdc545a5bef98c649d3cfbec4ac257 / app / page / channel.js

1862 bytesRaw
1const nest = require('depnest')
2const { h, computed } = require('mutant')
3const More = require('hypermore')
4const morphdom = require('morphdom')
5const get = require('lodash/get')
6
7exports.gives = nest('app.page.channel')
8
9exports.needs = nest({
10 'app.html.link': 'first',
11 'app.html.blogCard': 'first',
12 'history.sync.push': 'first',
13 'state.obs.channel': 'first',
14 'translations.sync.strings': 'first',
15})
16
17function latestUpdate(thread) {
18 var m = thread.timestamp
19 if(!thread.replies) return m
20
21 for(var i = 0; i < thread.replies.length; i++)
22 m = Math.max(thread.replies[i].timestamp, m)
23 return m
24}
25
26exports.create = (api) => {
27 return nest('app.page.channel', function (location) {
28 const { channel } = location
29 var strings = api.translations.sync.strings()
30
31 var channelObs = api.state.obs.channel(channel)
32
33 //disable "Show More" button when we are at the last thread.
34 var disableShowMore = computed([channelObs], threads => !!threads.ended)
35
36 var updates = h('div.threads', [])
37 var threadsHtmlObs = More(
38 channelObs,
39 function render (threads) {
40 morphdom(updates,
41 h('div.threads', Object.keys(threads.roots)
42 .map(id => threads.roots[id])
43 .filter(thread => get(thread, 'value.content.channel') == channel)
44 .sort((a, b) => latestUpdate(b) - latestUpdate(a))
45 .map(thread => api.app.html.blogCard(thread))
46 )
47 )
48 return updates
49 }
50 )
51
52 const Link = api.app.html.link
53
54 return h('Page -home', {title: channel}, [
55 Link({ page: 'threadNew', channel }, h('Button -primary', strings.channel.action.newThread)),
56 h('div.content', [ threadsHtmlObs ]),
57 h('Button -showMore', {
58 'ev-click': threadsHtmlObs.more,
59 disabled: disableShowMore
60 }, [strings.showMore])
61 ])
62 })
63}
64
65
66

Built with git-ssb-web