git ssb

2+

mixmix / ticktack



Tree: 35d82e967f4f37b646af2fa7cc7dfbfa54e01afc

Files: 35d82e967f4f37b646af2fa7cc7dfbfa54e01afc / app / page / channel.js

2224 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.threadCard': 'first',
10 'history.sync.push': 'first',
11 'state.obs.channel': 'first',
12 'translations.sync.strings': 'first',
13})
14
15function latestUpdate(thread) {
16 var m = thread.timestamp
17 if(!thread.replies) return m
18
19 for(var i = 0; i < thread.replies.length; i++)
20 m = Math.max(thread.replies[i].timestamp, m)
21 return m
22}
23
24exports.create = (api) => {
25 return nest('app.page.channel', function (location) {
26 // location here can expected to be: { page: 'home' }
27 var strings = api.translations.sync.strings()
28
29 var container = h('div.container', [])
30
31 var channelObs = api.state.obs.channel(location.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 threadsHtmlObs = More(
37 channelObs,
38 function render (threads) {
39 morphdom(container,
40 // LEGACY: some of these containers could be removed
41 // but they are here to be compatible with the old MCSS.
42 h('div.container', [
43 //private section
44 h('section.updates -directMessage', [
45 h('div.threads',
46 Object.keys(threads.roots)
47 .map(function (id) {
48 return threads.roots[id]
49 })
50 .filter(function (thread) {
51 return thread.value && thread.value.content.channel == location.channel
52 })
53 .sort(function (a, b) {
54 return latestUpdate(b) - latestUpdate(a)
55 })
56 .map(function (thread) {
57 return api.app.html.threadCard(thread)
58 })
59 )
60 ])
61 ])
62 )
63 return container
64 }
65 )
66
67 return h('Page -home', {title: location.channel}, [
68 threadsHtmlObs,
69 h('button', {
70 'ev-click': threadsHtmlObs.more,
71 disabled: disableShowMore
72 }, [strings.showMore])
73 ])
74 })
75}
76
77
78

Built with git-ssb-web