Files: 798294563ae751e766eb3b48905f401fc64fa61e / app / page / channelSubscriptions.js
2344 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 | mutantMap(mySubscriptions, api.app.html.channelCard), |
43 | h("p", "Loading...") |
44 | ) |
45 | ]) |
46 | ]) |
47 | |
48 | } |
49 | |
50 | if (location.scope === "friends") { |
51 | |
52 | myChannels = Value(false) |
53 | |
54 | onceTrue( |
55 | api.sbot.obs.connection, |
56 | sbot => { |
57 | sbot.channel.get((err, c) => { |
58 | if (err) throw err |
59 | let b = map(c, (v,k) => {return {channel: k, users: v}}) |
60 | b = sortBy(b, o => o.users.length) |
61 | myChannels.set(b.reverse().slice(0,100)) |
62 | }) |
63 | } |
64 | ) |
65 | |
66 | |
67 | displaySubscriptions = () => { |
68 | if (myChannels()) { |
69 | let subs = myChannels() |
70 | return subs.map(c => api.app.html.channelCard(c.channel)) |
71 | } |
72 | } |
73 | |
74 | return h('Page -channelSubscriptions', { title: strings.home }, [ |
75 | api.app.html.sideNav(location), |
76 | h('div.content', [ |
77 | when(myChannels, displaySubscriptions, h("p", strings.loading)) |
78 | ]) |
79 | ]) |
80 | } |
81 | }) |
82 | } |
83 | |
84 | |
85 | |
86 | |
87 |
Built with git-ssb-web