git ssb

2+

mixmix / ticktack



Tree: 1071420830e9c0d65973ba8c83523dba1402a931

Files: 1071420830e9c0d65973ba8c83523dba1402a931 / app / page / channel.js

2535 bytesRaw
1const nest = require('depnest')
2const { h, computed } = require('mutant')
3const {threadReduce} = require('ssb-reduce-stream')
4const pull = require('pull-stream')
5const isObject = require('lodash/isObject')
6const isString = require('lodash/isString')
7const last = require('lodash/last')
8const get = require('lodash/get')
9const More = require('hypermore')
10const morphdom = require('morphdom')
11const Debounce = require('obv-debounce')
12const PullObv = require('pull-obv')
13const Computed = require('mutant/computed')
14
15exports.gives = nest('app.page.channel')
16
17exports.needs = nest({
18 'app.html.nav': 'first',
19 'history.sync.push': 'first',
20 'translations.sync.strings': 'first',
21 'app.html.threadCard': 'first',
22 'state.obs.channel': 'first',
23})
24
25function latestUpdate(thread) {
26 var m = thread.timestamp
27 if(!thread.replies) return m
28
29 for(var i = 0; i < thread.replies.length; i++)
30 m = Math.max(thread.replies[i].timestamp, m)
31 return m
32}
33
34exports.create = (api) => {
35 return nest('app.page.channel', function (location) {
36 // location here can expected to be: { page: 'home' }
37 var strings = api.translations.sync.strings()
38
39 var container = h('div.container', [])
40
41 var channelObs = api.state.obs.channel(location.channel)
42
43 //disable "Show More" button when we are at the last thread.
44 var disableShowMore = Computed([channelObs], function (threads) {
45 return !!threads.ended
46 })
47
48 var threadsHtmlObs = More(
49 channelObs,
50 function render (threads) {
51
52 morphdom(container,
53 // LEGACY: some of these containers could be removed
54 // but they are here to be compatible with the old MCSS.
55 h('div.container', [
56 //private section
57 h('section.updates -directMessage', [
58 h('div.threads',
59 Object.keys(threads.roots)
60 .map(function (id) {
61 return threads.roots[id]
62 })
63 .sort(function (a, b) {
64 return latestUpdate(b) - latestUpdate(a)
65 })
66 .map(function (thread) {
67 return api.app.html.threadCard(thread, opts)
68 })
69 )
70 ])
71 ])
72 )
73 return container
74 }
75 )
76
77 return h('Page -home', [
78 h('h1', location.channel),
79 api.app.html.nav(),
80 threadsHtmlObs,
81 h('button', {
82 'ev-click': threadsHtmlObs.more,
83 disabled: disableShowMore
84 }, [strings.showMore])
85 ])
86 })
87}
88
89
90
91
92
93

Built with git-ssb-web