Files: f2c1e3d81bf5bba14c878872f1c99529d7eb2be5 / app / page / channel.js
2125 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, computed } = require('mutant') |
3 | const More = require('hypermore') |
4 | const morphdom = require('morphdom') |
5 | |
6 | exports.gives = nest('app.page.channel') |
7 | |
8 | exports.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 | |
16 | function 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 | |
25 | exports.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', [ |
67 | h('h1', location.channel), |
68 | api.app.html.nav(), |
69 | threadsHtmlObs, |
70 | h('button', { |
71 | 'ev-click': threadsHtmlObs.more, |
72 | disabled: disableShowMore |
73 | }, [strings.showMore]) |
74 | ]) |
75 | }) |
76 | } |
77 | |
78 |
Built with git-ssb-web