git ssb

2+

mixmix / ticktack



Tree: 36aff4f6d5e62e8ff308689bdfb6baea9413881e

Files: 36aff4f6d5e62e8ff308689bdfb6baea9413881e / app / page / channelSubscriptions.js

2373 bytesRaw
1const nest = require('depnest')
2const { h, watch, when, computed, Value, Set: MutantSet } = require('mutant')
3const pull = require('pull-stream')
4const Pushable = require('pull-pushable')
5const ref = require('ssb-ref')
6const throttle = require('mutant/throttle')
7const MutantPullReduce = require('mutant-pull-reduce')
8
9
10exports.gives = nest('app.page.channelSubscriptions')
11
12exports.needs = nest({
13 'app.html.sideNav': 'first',
14 'app.html.topNav': 'first',
15 'app.html.scroller': 'first',
16 'app.html.channelCard': 'first',
17
18 'history.sync.push': 'first',
19 'keys.sync.id': 'first',
20 'channel.obs.subscribed': 'first',
21 'channel.html.link': 'first',
22 'translations.sync.strings': 'first',
23 'sbot.async.friendsGet': 'first',
24 'sbot.pull.userFeed': 'first'
25})
26
27exports.create = (api) => {
28 return nest('app.page.channelSubscriptions', function (location) {
29 const strings = api.translations.sync.strings()
30 const myId = api.keys.sync.id()
31 const { subscribed } = api.channel.obs
32 let myChannels, displaySubscriptions
33
34 if (location.scope === "user") {
35 myChannels = subscribed(myId)
36 displaySubscriptions = () => [...myChannels().values()].map(c => api.app.html.channelCard(c))
37
38 return h('Page -channelSubscriptions', { title: strings.home }, [
39 api.app.html.sideNav(location),
40 h('div.content', [
41 //api.app.html.topNav(location),
42 when(myChannels, displaySubscriptions, h("p", "Loading..."))
43 ])
44 ])
45
46 }
47
48 if (location.scope === "friends") {
49
50 function createStream() {
51 var p = Pushable(true) // optionally pass `onDone` after it
52
53 api.sbot.async.friendsGet({ dest: myId }, (err, friends) => {
54 for (f in friends) {
55 var s = subscribed(f)
56 s(c => [...c].map(x => p.push(x)))
57 }
58 })
59
60 return p.source
61 }
62
63 var stream = createStream()
64 var opts = {
65 startValue: new Set(),
66 nextTick: true
67 }
68
69 var channelList = api.app.html.scroller({
70 classList: ['content'],
71 stream: createStream,
72 render
73 })
74
75 function render(channel) {
76 return api.app.html.channelCard(channel)
77 }
78
79 return h('Page -channelSubscriptions', { title: strings.home }, [
80 api.app.html.sideNav(location),
81 channelList
82 ])
83 }
84 })
85}
86
87
88
89
90

Built with git-ssb-web