git ssb

2+

mixmix / ticktack



Tree: b562e05b785dd3f68360267ec1b32b9c9e775278

Files: b562e05b785dd3f68360267ec1b32b9c9e775278 / app / page / channel.js

2099 bytesRaw
1const nest = require('depnest')
2const { h, computed } = require('mutant')
3const More = require('hypermore')
4const morphdom = require('morphdom')
5
6exports.gives = nest('app.page.channel')
7
8exports.needs = nest({
9 'app.html.nav': 'first',
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 // location here can expected to be: { page: 'home' }
28 var strings = api.translations.sync.strings()
29
30 var container = h('div.container', [])
31
32 var channelObs = api.state.obs.channel(location.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
41 morphdom(container,
42 // LEGACY: some of these containers could be removed
43 // but they are here to be compatible with the old MCSS.
44 h('div.container', [
45 //private section
46 h('section.updates -directMessage', [
47 h('div.threads',
48 Object.keys(threads.roots)
49 .map(function (id) {
50 return threads.roots[id]
51 })
52 .sort(function (a, b) {
53 return latestUpdate(b) - latestUpdate(a)
54 })
55 .map(function (thread) {
56 return api.app.html.threadCard(thread)
57 })
58 )
59 ])
60 ])
61 )
62 return container
63 }
64 )
65
66 return h('Page -home', {title: location.channel}, [
67 threadsHtmlObs,
68 h('button', {
69 'ev-click': threadsHtmlObs.more,
70 disabled: disableShowMore
71 }, [strings.showMore])
72 ])
73 })
74}
75
76
77

Built with git-ssb-web