Files: 6a83e79b4f03d4de17ec9cb6ac84f25423f5ac0a / app / page / channel.js
2073 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.threadCard': 'first', |
10 | 'history.sync.push': 'first', |
11 | 'state.obs.channel': 'first', |
12 | 'translations.sync.strings': 'first', |
13 | }) |
14 | |
15 | function 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 | |
24 | exports.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 | |
40 | morphdom(container, |
41 | // LEGACY: some of these containers could be removed |
42 | // but they are here to be compatible with the old MCSS. |
43 | h('div.container', [ |
44 | //private section |
45 | h('section.updates -directMessage', [ |
46 | h('div.threads', |
47 | Object.keys(threads.roots) |
48 | .map(function (id) { |
49 | return threads.roots[id] |
50 | }) |
51 | .sort(function (a, b) { |
52 | return latestUpdate(b) - latestUpdate(a) |
53 | }) |
54 | .map(function (thread) { |
55 | return api.app.html.threadCard(thread) |
56 | }) |
57 | ) |
58 | ]) |
59 | ]) |
60 | ) |
61 | return container |
62 | } |
63 | ) |
64 | |
65 | return h('Page -home', {title: location.channel}, [ |
66 | threadsHtmlObs, |
67 | h('button', { |
68 | 'ev-click': threadsHtmlObs.more, |
69 | disabled: disableShowMore |
70 | }, [strings.showMore]) |
71 | ]) |
72 | }) |
73 | } |
74 | |
75 | |
76 | |
77 |
Built with git-ssb-web