git ssb

2+

mixmix / ticktack



Tree: 17ff653872ea29756b16c13932a8b662d5e1b663

Files: 17ff653872ea29756b16c13932a8b662d5e1b663 / app / page / channel.js

1981 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 container = h('div.container', [])
31
32 var channelObs = api.state.obs.channel(channel)
33
34 //disable "Show More" button when we are at the last thread.
35 var disableShowMore = computed([channelObs], threads => !!threads.ended)
36
37 var threadsHtmlObs = More(
38 channelObs,
39 function render (threads) {
40 morphdom(container,
41 // LEGACY: some of these containers could be removed
42 // but they are here to be compatible with the old MCSS.
43 h('div.container', [
44 //private section
45 h('section.updates -directMessage', [
46 h('div.threads', Object.keys(threads.roots)
47 .map(id => threads.roots[id])
48 .filter(thread => get(thread, 'value.content.channel') == channel)
49 .sort((a, b) => latestUpdate(b) - latestUpdate(a))
50 .map(thread => api.app.html.threadCard(thread))
51 )
52 ])
53 ])
54 )
55 return container
56 }
57 )
58
59 return h('Page -home', {title: location.channel}, [
60 threadsHtmlObs,
61 h('button', {
62 'ev-click': threadsHtmlObs.more,
63 disabled: disableShowMore
64 }, [strings.showMore])
65 ])
66 })
67}
68
69
70

Built with git-ssb-web