git ssb

2+

mixmix / ticktack



Tree: 8c68dbb9a3b69a0cf0e0dd503ef059a873189cd5

Files: 8c68dbb9a3b69a0cf0e0dd503ef059a873189cd5 / app / page / channelSubscriptions.js

2788 bytesRaw
1const nest = require('depnest')
2const { h, when, Value, Array: MutantArray, onceTrue, computed, map: mutantMap } = require('mutant')
3const sortBy = require('lodash/sortBy')
4const map = require('lodash/map')
5const difference = require('lodash/difference')
6
7exports.gives = nest('app.page.channelSubscriptions')
8
9exports.needs = nest({
10 'app.html.sideNav': 'first',
11 'app.html.topNav': 'first',
12 'app.html.scroller': 'first',
13 'app.html.channelCard': 'first',
14 'history.sync.push': 'first',
15 'keys.sync.id': 'first',
16 'channel.obs.subscribed': 'first',
17 'channel.obs.recent':'first',
18 'channel.html.link': 'first',
19 'translations.sync.strings': 'first',
20 'sbot.async.friendsGet': 'first',
21 'sbot.pull.userFeed': 'first',
22 'sbot.obs.connection': 'first'
23})
24
25exports.create = (api) => {
26 const otherChannels = MutantArray ()
27
28 return nest('app.page.channelSubscriptions', function (location) {
29 const strings = api.translations.sync.strings()
30 const myId = api.keys.sync.id()
31
32 const rawSubs = api.channel.obs.subscribed(myId)
33 const mySubs = computed(rawSubs, myChannels => [...myChannels.values()].reverse() )
34
35 if (location.scope === "user") {
36
37 return h('Page -channelSubscriptions', { title: strings.home }, [
38 api.app.html.sideNav(location),
39 h('div.content', [
40 when(rawSubs.sync,
41 [
42 computed(mySubs, mys => mys.length === 0 ? strings.subscriptions.state.noSubscriptions : ''),
43 mutantMap(mySubs, api.app.html.channelCard),
44 ],
45 h('p', strings.loading)
46 )
47 ])
48 ])
49 }
50
51 if (location.scope === "friends") {
52 // update list of other all channels
53 onceTrue(
54 api.sbot.obs.connection,
55 sbot => {
56 sbot.channel.subscriptions((err, c) => {
57 if (err) throw err
58 let b = map(c, (v,k) => {return {channel: k, users: v}})
59 b = sortBy(b, o => o.users.length)
60 let res = b.reverse()
61
62 otherChannels.set(res.map(c => c.channel))
63 })
64 }
65 )
66
67 const showMoreCounter = Value(1)
68 const newChannels = computed([otherChannels, mySubs, showMoreCounter], (other, mine, more) => {
69 return difference(other, mine)
70 .slice(0, 10*more)
71 })
72
73 return h('Page -channelSubscriptions', { title: strings.home }, [
74 api.app.html.sideNav(location),
75 h('div.content', [
76 when(otherChannels,
77 [
78 mutantMap(newChannels, api.app.html.channelCard),
79 h('Button', { 'ev-click': () => showMoreCounter.set(showMoreCounter()+1) },
80 strings.showMore
81 )
82 ],
83 h('p', strings.loading)
84 )
85 ])
86 ])
87 }
88 })
89}
90
91
92

Built with git-ssb-web