git ssb

2+

mixmix / ticktack



Commit b3fdce7b121819753c77c856de809a9b91b884b5

issue #70: refactoring PR according to @mixmix feedback. WIP

andre alves garzia committed on 2/5/2018, 4:12:41 PM
Parent: bf773c764144ae29c9dbe4469dba56760ba6a6df

Files changed

.gitignorechanged
app/html/channelCard.jschanged
app/html/sideNav/sideNavDiscovery.jschanged
app/page/channelShow.jschanged
app/page/channelSubscriptions.jschanged
channel/index.jschanged
channel/sync.jsdeleted
channel/obs.jsadded
translations/en.jschanged
.gitignoreView
@@ -1,2 +1,3 @@
11 node_modules
22 package-lock.json
3+.idea
app/html/channelCard.jsView
@@ -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')
83
4+
95 exports.gives = nest('app.html.channelCard')
106
117 exports.needs = nest({
128 'keys.sync.id': 'first',
@@ -14,27 +10,21 @@
1410 'translations.sync.strings': 'first',
1511 'channel.obs.subscribed': 'first',
1612 'channel.async.subscribe': 'first',
1713 'channel.async.unsubscribe': 'first',
18- 'channel.sync.isSubscribedTo': 'first',
14+ 'channel.obs.isSubscribedTo': 'first',
1915 })
2016
2117 exports.create = function (api) {
2218
2319 return nest('app.html.channelCard', (channel) => {
24- var strings = api.translations.sync.strings()
20+ const strings = api.translations.sync.strings()
2521
2622 const myId = api.keys.sync.id()
27- const { subscribed } = api.channel.obs
2823 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)
3326
34- let cb = () => {
35- youSubscribe.set(isSubscribedTo(channel, myId))
36- }
3727
3828 const goToChannel = (e, channel) => {
3929 e.stopPropagation()
4030
@@ -45,10 +35,10 @@
4535 h('div.content', [
4636 h('div.text', [
4737 h('h2', {'ev-click': ev => goToChannel(ev, channel)}, channel),
4838 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)
5141 ),
5242 ])
5343 ])
5444 ])
app/html/sideNav/sideNavDiscovery.jsView
@@ -137,9 +137,9 @@
137137 Option({
138138 imageEl: h('i', [
139139 h('img', { src: path.join(__dirname, '../../../assets', 'discover.png') })
140140 ]),
141- label: "My subscriptions",
141+ label: strings.subscriptions.user,
142142 selected: isDiscoverLocation(location),
143143 location: { page: 'channelSubscriptions', scope: 'user' },
144144 }),
145145
@@ -147,9 +147,9 @@
147147 Option({
148148 imageEl: h('i', [
149149 h('img', { src: path.join(__dirname, '../../../assets', 'discover.png') })
150150 ]),
151- label: "Friends subscriptions",
151+ label: strings.subscriptions.friends,
152152 selected: isDiscoverLocation(location),
153153 location: { page: 'channelSubscriptions', scope: 'friends' },
154154 })
155155 ]
app/page/channelShow.jsView
@@ -10,18 +10,15 @@
1010 'app.html.scroller': 'first',
1111 'app.html.blogCard': 'first',
1212 'channel.obs.recent': 'first',
1313 'feed.pull.channel': 'first',
14- 'feed.pull.public': 'first',
1514 'history.sync.push': 'first',
1615 'keys.sync.id': 'first',
17- 'message.html.channel': 'first',
1816 'translations.sync.strings': 'first',
19- 'unread.sync.isUnread': 'first',
2017 'channel.obs.subscribed': 'first',
2118 'channel.async.subscribe': 'first',
2219 'channel.async.unsubscribe': 'first',
23- 'channel.sync.isSubscribedTo': 'first'
20+ 'channel.obs.isSubscribedTo': 'first'
2421 })
2522
2623 exports.create = (api) => {
2724 return nest('app.page.channelShow', channelShow)
@@ -31,12 +28,10 @@
3128 var strings = api.translations.sync.strings()
3229 const myId = api.keys.sync.id()
3330 const { subscribed } = api.channel.obs
3431 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)
3934
4035 let cb = () => {
4136 youSubscribe.set(isSubscribedTo(location.channel, myId))
4237 }
app/page/channelSubscriptions.jsView
@@ -50,27 +50,8 @@
5050 }
5151
5252 if (location.scope === "friends") {
5353
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-
7354 myChannels = Value(false)
7455
7556 onceTrue(
7657 api.sbot.obs.connection,
@@ -78,10 +59,9 @@
7859 sbot.channel.get((err, c) => {
7960 if (err) throw err
8061 let b = map(c, (v,k) => {return {channel: k, users: v}})
8162 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))
8464 })
8565 }
8666 )
8767
@@ -95,28 +75,11 @@
9575
9676 return h('Page -channelSubscriptions', { title: strings.home }, [
9777 api.app.html.sideNav(location),
9878 h('div.content', [
99- //api.app.html.topNav(location),
100- when(myChannels, displaySubscriptions, h("p", "Loading..."))
79+ when(myChannels, displaySubscriptions, h("p", strings.loading))
10180 ])
10281 ])
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- // ])
11982 }
12083 })
12184 }
12285
channel/index.jsView
@@ -1,6 +1,6 @@
11 module.exports = {
22 async: require('./async'),
3- sync: require('./sync')
3+ obs: require('./obs')
44 }
55
66
channel/sync.jsView
@@ -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.jsView
@@ -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+}
translations/en.jsView
@@ -136,8 +136,12 @@
136136 subscribe: 'Subscribe',
137137 unsubscribe: 'Unsubscribe'
138138 }
139139 },
140+ subscriptions: {
141+ user: "My subscriptions",
142+ friends: "Friends subscriptions"
143+ },
140144 languages: {
141145 en: 'English',
142146 zh: '中文'
143147 }

Built with git-ssb-web