Files: 2f8b5a42a327baeb86c4cc6af56c65848948d0ec / app / page / channelSubscriptions.js
2437 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, when, Value, onceTrue, computed, map: mutantMap } = require('mutant') |
3 | const sortBy = require('lodash/sortBy') |
4 | const map = require("lodash/map") |
5 | |
6 | |
7 | exports.gives = nest('app.page.channelSubscriptions') |
8 | |
9 | exports.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 | |
25 | exports.create = (api) => { |
26 | return nest('app.page.channelSubscriptions', function (location) { |
27 | const strings = api.translations.sync.strings() |
28 | const myId = api.keys.sync.id() |
29 | const { subscribed } = api.channel.obs |
30 | let myChannels, displaySubscriptions |
31 | |
32 | if (location.scope === "user") { |
33 | myChannels = subscribed(myId) |
34 | |
35 | const mySubscriptions = computed(myChannels, myChannels => [...myChannels.values()]) |
36 | |
37 | return h('Page -channelSubscriptions', { title: strings.home }, [ |
38 | api.app.html.sideNav(location), |
39 | h('div.content', [ |
40 | //api.app.html.topNav(location), |
41 | when(myChannels, |
42 | myChannels().size === 0 |
43 | ? strings.subscriptions.state.noSubscriptions |
44 | :'' |
45 | ), |
46 | when(myChannels, |
47 | mutantMap(mySubscriptions, api.app.html.channelCard), |
48 | h("p", strings.loading) |
49 | ) |
50 | ]) |
51 | ]) |
52 | |
53 | } |
54 | |
55 | if (location.scope === "friends") { |
56 | |
57 | myChannels = Value(false) |
58 | |
59 | onceTrue( |
60 | api.sbot.obs.connection, |
61 | sbot => { |
62 | sbot.channel.get((err, c) => { |
63 | if (err) throw err |
64 | let b = map(c, (v,k) => {return {channel: k, users: v}}) |
65 | b = sortBy(b, o => o.users.length) |
66 | let res = b.reverse().slice(0,100) |
67 | |
68 | myChannels.set(res.map(c => c.channel)) |
69 | }) |
70 | } |
71 | ) |
72 | |
73 | |
74 | return h('Page -channelSubscriptions', { title: strings.home }, [ |
75 | api.app.html.sideNav(location), |
76 | h('div.content', [ |
77 | when(myChannels, |
78 | mutantMap(myChannels, api.app.html.channelCard), |
79 | h("p", strings.loading) |
80 | ) |
81 | ]) |
82 | ]) |
83 | } |
84 | }) |
85 | } |
86 | |
87 | |
88 | |
89 | |
90 |
Built with git-ssb-web