Files: 60479658b26b297158dd59938d021562a5b447ec / app / page / channel.js
2535 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, computed } = require('mutant') |
3 | const {threadReduce} = require('ssb-reduce-stream') |
4 | const pull = require('pull-stream') |
5 | const isObject = require('lodash/isObject') |
6 | const isString = require('lodash/isString') |
7 | const last = require('lodash/last') |
8 | const get = require('lodash/get') |
9 | const More = require('hypermore') |
10 | const morphdom = require('morphdom') |
11 | const Debounce = require('obv-debounce') |
12 | const PullObv = require('pull-obv') |
13 | const Computed = require('mutant/computed') |
14 | |
15 | exports.gives = nest('app.page.channel') |
16 | |
17 | exports.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 | |
25 | function 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 | |
34 | exports.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