git ssb

2+

mixmix / ticktack



Tree: f98c407e53e9a0b812757db574e4a35fcff143d4

Files: f98c407e53e9a0b812757db574e4a35fcff143d4 / app / page / channel.js

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

Built with git-ssb-web