Commit b3fdce7b121819753c77c856de809a9b91b884b5
issue #70: refactoring PR according to @mixmix feedback. WIP
andre alves garzia committed on 2/5/2018, 4:12:41 PMParent: bf773c764144ae29c9dbe4469dba56760ba6a6df
Files changed
.gitignore | changed |
app/html/channelCard.js | changed |
app/html/sideNav/sideNavDiscovery.js | changed |
app/page/channelShow.js | changed |
app/page/channelSubscriptions.js | changed |
channel/index.js | changed |
channel/sync.js | deleted |
channel/obs.js | added |
translations/en.js | changed |
app/html/channelCard.js | ||
---|---|---|
@@ -1,12 +1,8 @@ | ||
1 | -var nest = require('depnest') | |
2 | -const { h, map, when, Value } = require('mutant') | |
3 | -var isString= require('lodash/isString') | |
4 | -var maxBy= require('lodash/maxBy') | |
5 | -var markdown = require('ssb-markdown') | |
6 | -var ref = require('ssb-ref') | |
7 | -var htmlEscape = require('html-escape') | |
1 | +const nest = require('depnest') | |
2 | +const { h, when, Value } = require('mutant') | |
8 | 3 | |
4 | + | |
9 | 5 | exports.gives = nest('app.html.channelCard') |
10 | 6 | |
11 | 7 | exports.needs = nest({ |
12 | 8 | 'keys.sync.id': 'first', |
@@ -14,27 +10,21 @@ | ||
14 | 10 | 'translations.sync.strings': 'first', |
15 | 11 | 'channel.obs.subscribed': 'first', |
16 | 12 | 'channel.async.subscribe': 'first', |
17 | 13 | 'channel.async.unsubscribe': 'first', |
18 | - 'channel.sync.isSubscribedTo': 'first', | |
14 | + 'channel.obs.isSubscribedTo': 'first', | |
19 | 15 | }) |
20 | 16 | |
21 | 17 | exports.create = function (api) { |
22 | 18 | |
23 | 19 | return nest('app.html.channelCard', (channel) => { |
24 | - var strings = api.translations.sync.strings() | |
20 | + const strings = api.translations.sync.strings() | |
25 | 21 | |
26 | 22 | const myId = api.keys.sync.id() |
27 | - const { subscribed } = api.channel.obs | |
28 | 23 | const { subscribe, unsubscribe } = api.channel.async |
29 | - const { isSubscribedTo } = api.channel.sync | |
30 | - const myChannels = subscribed(myId) | |
31 | - let cs = myChannels().values() | |
32 | - const youSubscribe = Value(isSubscribedTo(channel, myId)) | |
24 | + const { isSubscribedTo } = api.channel.obs | |
25 | + const youSubscribe = isSubscribedTo(channel, myId) | |
33 | 26 | |
34 | - let cb = () => { | |
35 | - youSubscribe.set(isSubscribedTo(channel, myId)) | |
36 | - } | |
37 | 27 | |
38 | 28 | const goToChannel = (e, channel) => { |
39 | 29 | e.stopPropagation() |
40 | 30 | |
@@ -45,10 +35,10 @@ | ||
45 | 35 | h('div.content', [ |
46 | 36 | h('div.text', [ |
47 | 37 | h('h2', {'ev-click': ev => goToChannel(ev, channel)}, channel), |
48 | 38 | when(youSubscribe, |
49 | - h('Button', { 'ev-click': () => unsubscribe(channel, cb) }, strings.channelShow.action.unsubscribe), | |
50 | - h('Button', { 'ev-click': () => subscribe(channel, cb) }, strings.channelShow.action.subscribe) | |
39 | + h('Button', { 'ev-click': () => unsubscribe(channel) }, strings.channelShow.action.unsubscribe), | |
40 | + h('Button', { 'ev-click': () => subscribe(channel) }, strings.channelShow.action.subscribe) | |
51 | 41 | ), |
52 | 42 | ]) |
53 | 43 | ]) |
54 | 44 | ]) |
app/html/sideNav/sideNavDiscovery.js | ||
---|---|---|
@@ -137,9 +137,9 @@ | ||
137 | 137 | Option({ |
138 | 138 | imageEl: h('i', [ |
139 | 139 | h('img', { src: path.join(__dirname, '../../../assets', 'discover.png') }) |
140 | 140 | ]), |
141 | - label: "My subscriptions", | |
141 | + label: strings.subscriptions.user, | |
142 | 142 | selected: isDiscoverLocation(location), |
143 | 143 | location: { page: 'channelSubscriptions', scope: 'user' }, |
144 | 144 | }), |
145 | 145 | |
@@ -147,9 +147,9 @@ | ||
147 | 147 | Option({ |
148 | 148 | imageEl: h('i', [ |
149 | 149 | h('img', { src: path.join(__dirname, '../../../assets', 'discover.png') }) |
150 | 150 | ]), |
151 | - label: "Friends subscriptions", | |
151 | + label: strings.subscriptions.friends, | |
152 | 152 | selected: isDiscoverLocation(location), |
153 | 153 | location: { page: 'channelSubscriptions', scope: 'friends' }, |
154 | 154 | }) |
155 | 155 | ] |
app/page/channelShow.js | ||
---|---|---|
@@ -10,18 +10,15 @@ | ||
10 | 10 | 'app.html.scroller': 'first', |
11 | 11 | 'app.html.blogCard': 'first', |
12 | 12 | 'channel.obs.recent': 'first', |
13 | 13 | 'feed.pull.channel': 'first', |
14 | - 'feed.pull.public': 'first', | |
15 | 14 | 'history.sync.push': 'first', |
16 | 15 | 'keys.sync.id': 'first', |
17 | - 'message.html.channel': 'first', | |
18 | 16 | 'translations.sync.strings': 'first', |
19 | - 'unread.sync.isUnread': 'first', | |
20 | 17 | 'channel.obs.subscribed': 'first', |
21 | 18 | 'channel.async.subscribe': 'first', |
22 | 19 | 'channel.async.unsubscribe': 'first', |
23 | - 'channel.sync.isSubscribedTo': 'first' | |
20 | + 'channel.obs.isSubscribedTo': 'first' | |
24 | 21 | }) |
25 | 22 | |
26 | 23 | exports.create = (api) => { |
27 | 24 | return nest('app.page.channelShow', channelShow) |
@@ -31,12 +28,10 @@ | ||
31 | 28 | var strings = api.translations.sync.strings() |
32 | 29 | const myId = api.keys.sync.id() |
33 | 30 | const { subscribed } = api.channel.obs |
34 | 31 | const { subscribe, unsubscribe } = api.channel.async |
35 | - const { isSubscribedTo } = api.channel.sync | |
36 | - const myChannels = subscribed(myId) | |
37 | - let cs = myChannels().values() | |
38 | - const youSubscribe = Value(isSubscribedTo(location.channel, myId)) | |
32 | + const { isSubscribedTo } = api.channel.obs | |
33 | + const youSubscribe = isSubscribedTo(location.channel, myId) | |
39 | 34 | |
40 | 35 | let cb = () => { |
41 | 36 | youSubscribe.set(isSubscribedTo(location.channel, myId)) |
42 | 37 | } |
app/page/channelSubscriptions.js | ||
---|---|---|
@@ -50,27 +50,8 @@ | ||
50 | 50 | } |
51 | 51 | |
52 | 52 | if (location.scope === "friends") { |
53 | 53 | |
54 | - // function createStream() { | |
55 | - // var p = Pushable(true) // optionally pass `onDone` after it | |
56 | - | |
57 | - // api.sbot.async.friendsGet({ dest: myId }, (err, friends) => { | |
58 | - // for (f in friends) { | |
59 | - // var s = subscribed(f) | |
60 | - // s(c => [...c].map(x => p.push(x))) | |
61 | - // } | |
62 | - // }) | |
63 | - | |
64 | - // return p.source | |
65 | - // } | |
66 | - | |
67 | - // var stream = createStream() | |
68 | - // var opts = { | |
69 | - // startValue: new Set(), | |
70 | - // nextTick: true | |
71 | - // } | |
72 | - | |
73 | 54 | myChannels = Value(false) |
74 | 55 | |
75 | 56 | onceTrue( |
76 | 57 | api.sbot.obs.connection, |
@@ -78,10 +59,9 @@ | ||
78 | 59 | sbot.channel.get((err, c) => { |
79 | 60 | if (err) throw err |
80 | 61 | let b = map(c, (v,k) => {return {channel: k, users: v}}) |
81 | 62 | b = sortBy(b, o => o.users.length) |
82 | - myChannels.set(b.reverse().slice(1,101)) | |
83 | - // console.log(`want blog ${blog}, callback: ${success}`) | |
63 | + myChannels.set(b.reverse().slice(0,100)) | |
84 | 64 | }) |
85 | 65 | } |
86 | 66 | ) |
87 | 67 | |
@@ -95,28 +75,11 @@ | ||
95 | 75 | |
96 | 76 | return h('Page -channelSubscriptions', { title: strings.home }, [ |
97 | 77 | api.app.html.sideNav(location), |
98 | 78 | h('div.content', [ |
99 | - //api.app.html.topNav(location), | |
100 | - when(myChannels, displaySubscriptions, h("p", "Loading...")) | |
79 | + when(myChannels, displaySubscriptions, h("p", strings.loading)) | |
101 | 80 | ]) |
102 | 81 | ]) |
103 | - | |
104 | - // var channelList = api.app.html.scroller({ | |
105 | - // classList: ['content'], | |
106 | - // stream: sbot.channel.stream, | |
107 | - // render | |
108 | - // }) | |
109 | - | |
110 | - // function render(channel) { | |
111 | - // console.assert.log("render", channel) | |
112 | - // return api.app.html.channelCard(channel) | |
113 | - // } | |
114 | - | |
115 | - // return h('Page -channelSubscriptions', { title: strings.home }, [ | |
116 | - // api.app.html.sideNav(location), | |
117 | - // //channelList | |
118 | - // ]) | |
119 | 82 | } |
120 | 83 | }) |
121 | 84 | } |
122 | 85 |
channel/index.js | ||
---|---|---|
@@ -1,6 +1,6 @@ | ||
1 | 1 | module.exports = { |
2 | 2 | async: require('./async'), |
3 | - sync: require('./sync') | |
3 | + obs: require('./obs') | |
4 | 4 | } |
5 | 5 | |
6 | 6 |
channel/sync.js | ||
---|---|---|
@@ -1,24 +1,0 @@ | ||
1 | -var nest = require('depnest') | |
2 | -var ref = require('ssb-ref') | |
3 | - | |
4 | -exports.needs = nest({ | |
5 | - 'keys.sync.id': 'first', | |
6 | - 'channel.obs.subscribed': 'first', | |
7 | -}) | |
8 | - | |
9 | -exports.gives = nest('channel.sync.isSubscribedTo') | |
10 | - | |
11 | -exports.create = function (api) { | |
12 | - return nest('channel.sync.isSubscribedTo', isSubscribedTo) | |
13 | - | |
14 | - function isSubscribedTo (channel, id) { | |
15 | - if (!ref.isFeed(id)) { | |
16 | - id = api.keys.sync.id() | |
17 | - } | |
18 | - | |
19 | - const { subscribed } = api.channel.obs | |
20 | - const myChannels = subscribed(id) | |
21 | - let v = myChannels().values() | |
22 | - return [...v].includes(channel) | |
23 | - } | |
24 | -} |
channel/obs.js | ||
---|---|---|
@@ -1,0 +1,24 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const ref = require('ssb-ref') | |
3 | +const computed = require('mutant/computed') | |
4 | + | |
5 | +exports.needs = nest({ | |
6 | + 'keys.sync.id': 'first', | |
7 | + 'channel.obs.subscribed': 'first', | |
8 | +}) | |
9 | + | |
10 | +exports.gives = nest('channel.obs.isSubscribedTo') | |
11 | + | |
12 | +exports.create = function (api) { | |
13 | + return nest('channel.obs.isSubscribedTo', isSubscribedTo) | |
14 | + | |
15 | + function isSubscribedTo (channel, id) { | |
16 | + if (!ref.isFeed(id)) { | |
17 | + id = api.keys.sync.id() | |
18 | + } | |
19 | + | |
20 | + const { subscribed } = api.channel.obs | |
21 | + const myChannels = subscribed(id) | |
22 | + return computed([myChannels], (v) => [...v].includes(channel)) | |
23 | + } | |
24 | +} |
Built with git-ssb-web