git ssb

2+

mixmix / ticktack



Tree: 0f3f8657225d9eb6e00c551660cc3a05e760c3bd

Files: 0f3f8657225d9eb6e00c551660cc3a05e760c3bd / app / page / channel.js

1897 bytesRaw
1const nest = require('depnest')
2const { h, computed } = require('mutant')
3const More = require('hypermore')
4const morphdom = require('morphdom')
5const get = require('lodash/get')
6
7exports.gives = nest('app.page.channel')
8
9exports.needs = nest({
10 'app.html.link': 'first',
11 'app.html.blogCard': 'first',
12 'history.sync.push': 'first',
13 'state.obs.channel': 'first',
14 'translations.sync.strings': 'first'
15})
16
17function latestUpdate (thread) {
18 var m = thread.timestamp
19 if (!thread.replies) return m
20
21 for (var i = 0; i < thread.replies.length; i++) { m = Math.max(thread.replies[i].timestamp, m) }
22 return m
23}
24
25exports.create = (api) => {
26 return nest('app.page.channel', function (location) {
27 const { channel } = location
28 var strings = api.translations.sync.strings()
29
30 var channelObs = api.state.obs.channel(channel)
31
32 // disable "Show More" button when we are at the last thread.
33 var disableShowMore = computed([channelObs], threads => !!threads.ended)
34
35 var updates = h('div.threads', [])
36 var threadsHtmlObs = More(
37 channelObs,
38 function render (threads) {
39 morphdom(updates,
40 h('div.threads', Object.keys(threads.roots)
41 .map(id => threads.roots[id])
42 .filter(thread => get(thread, 'value.content.channel') == channel)
43 .sort((a, b) => latestUpdate(b) - latestUpdate(a))
44 .map(thread => api.app.html.blogCard(thread))
45 )
46 )
47 return updates
48 }
49 )
50
51 const Link = api.app.html.link
52
53 // TODO change this to -channel
54 return h('Page -home', {title: channel}, [
55 Link({ page: 'threadNew', channel }, h('Button -strong', strings.channel.action.newThread)),
56 h('div.content', [ threadsHtmlObs ]),
57 h('Button -showMore', {
58 'ev-click': threadsHtmlObs.more,
59 disabled: disableShowMore
60 }, [strings.showMore])
61 ])
62 })
63}
64

Built with git-ssb-web