git ssb

2+

mixmix / ticktack



Commit e7cb9fed92d71db542d760efdf0e11216374124f

Merge branch 'master' of github.com:ticktackim/ticktack-workplan

mix irving committed on 2/12/2018, 4:09:35 AM
Parent: c3ca882d159804f4fd41554698ec61ae21d435b2
Parent: b54653fc52f7f7d05a4fc1e294bb6151561bff09

Files changed

app/html/channelCard.jschanged
app/page/channelShow.jschanged
app/page/channelSubscriptions.jschanged
app/page/channelSubscriptions.mcsschanged
app/page/page.mcsschanged
channel/index.jschanged
channel/obs.jschanged
channel/html/subscribe.jsadded
package.jsonchanged
app/html/channelCard.jsView
@@ -1,43 +1,40 @@
11 const nest = require('depnest')
22 const { h, when } = require('mutant')
33
4-
54 exports.gives = nest('app.html.channelCard')
65
76 exports.needs = nest({
8- 'keys.sync.id': 'first',
9- 'history.sync.push': 'first',
10- 'translations.sync.strings': 'first',
11- 'channel.obs.subscribed': 'first',
12- 'channel.async.subscribe': 'first',
13- 'channel.async.unsubscribe': 'first',
14- 'channel.obs.isSubscribedTo': 'first',
7+ 'keys.sync.id': 'first',
8+ 'history.sync.push': 'first',
9+ 'translations.sync.strings': 'first',
10+ 'channel.obs.subscribed': 'first',
11+ 'channel.obs.isSubscribedTo': 'first',
12+ 'channel.async.subscribe': 'first',
13+ 'channel.async.unsubscribe': 'first',
14+ 'channel.html.subscribe': 'first',
1515 })
1616
1717 exports.create = function (api) {
1818
19- return nest('app.html.channelCard', (channel) => {
20- const strings = api.translations.sync.strings()
21- const myId = api.keys.sync.id()
22- const { subscribe, unsubscribe } = api.channel.async
23- const { isSubscribedTo } = api.channel.obs
24- const youSubscribe = isSubscribedTo(channel, myId)
25-
26- const goToChannel = () => {
27- api.history.sync.push({ page: 'channelShow', channel: channel })
28- }
29-
30- return h('ChannelCard', [
31- h('div.content', [
32- h('div.text', [
33- h('h2', {'ev-click': goToChannel}, channel),
34- when(youSubscribe,
35- h('Button', { 'ev-click': () => unsubscribe(channel) }, strings.channelShow.action.unsubscribe),
36- h('Button', { 'ev-click': () => subscribe(channel) }, strings.channelShow.action.subscribe)
37- ),
38- ])
39- ])
19+ return nest('app.html.channelCard', (channel) => {
20+ const strings = api.translations.sync.strings()
21+ const myId = api.keys.sync.id()
22+ const { subscribe, unsubscribe } = api.channel.async
23+ const { isSubscribedTo } = api.channel.obs
24+ const youSubscribe = isSubscribedTo(channel, myId)
25+
26+ const goToChannel = () => {
27+ api.history.sync.push({ page: 'channelShow', channel: channel })
28+ }
29+
30+ return h('ChannelCard', [
31+ h('div.content', [
32+ h('div.text', [
33+ h('h2', {'ev-click': goToChannel}, channel),
34+ api.channel.html.subscribe(channel)
4035 ])
41- })
36+ ])
37+ ])
38+ })
4239 }
4340
app/page/channelShow.jsView
@@ -8,47 +8,31 @@
88 'app.html.sideNav': 'first',
99 'app.html.topNav': 'first',
1010 'app.html.scroller': 'first',
1111 'app.html.blogCard': 'first',
12- 'channel.obs.recent': 'first',
1312 'feed.pull.channel': 'first',
1413 'history.sync.push': 'first',
15- 'keys.sync.id': 'first',
1614 'translations.sync.strings': 'first',
17- 'channel.obs.subscribed': 'first',
18- 'channel.async.subscribe': 'first',
19- 'channel.async.unsubscribe': 'first',
20- 'channel.obs.isSubscribedTo': 'first'
15+ 'channel.obs.recent': 'first',
16+ 'channel.html.subscribe': 'first'
2117 })
2218
2319 exports.create = (api) => {
2420 return nest('app.page.channelShow', channelShow)
2521
2622 function channelShow(location) {
27-
2823 var strings = api.translations.sync.strings()
29- const myId = api.keys.sync.id()
30- const { subscribed } = api.channel.obs
31- const { subscribe, unsubscribe } = api.channel.async
32- const { isSubscribedTo } = api.channel.obs
33- const youSubscribe = isSubscribedTo(location.channel, myId)
3424
3525 var searchVal = resolve(location.channel)
3626
37-
38-
3927 createStream = api.feed.pull.channel(location.channel)
40-
4128
4229 const prepend = [
4330 api.app.html.topNav(location),
4431 h('section.about', [
4532 h('h1', location.channel),
4633 h('div.actions', [
47- when(youSubscribe,
48- h('Button', { 'ev-click': () => subscribe(location.channel) }, strings.channelShow.action.unsubscribe),
49- h('Button', { 'ev-click': () => unsubscribe(location.channel) }, strings.channelShow.action.subscribe)
50- )
34+ api.channel.html.subscribe(location.channel)
5135 ])
5236 ]),
5337 ]
5438
app/page/channelSubscriptions.jsView
@@ -1,10 +1,10 @@
11 const nest = require('depnest')
2-const { h, when, Value, onceTrue, computed, map: mutantMap } = require('mutant')
2+const { h, when, Value, Array: MutantArray, onceTrue, computed, map: mutantMap } = require('mutant')
33 const sortBy = require('lodash/sortBy')
4-const map = require("lodash/map")
4+const map = require('lodash/map')
5+const difference = require('lodash/difference')
56
6-
77 exports.gives = nest('app.page.channelSubscriptions')
88
99 exports.needs = nest({
1010 'app.html.sideNav': 'first',
@@ -22,68 +22,70 @@
2222 'sbot.obs.connection': 'first'
2323 })
2424
2525 exports.create = (api) => {
26+ const otherChannels = MutantArray ()
27+
2628 return nest('app.page.channelSubscriptions', function (location) {
2729 const strings = api.translations.sync.strings()
2830 const myId = api.keys.sync.id()
29- const { subscribed } = api.channel.obs
30- let myChannels, displaySubscriptions
3131
32+ const rawSubs = api.channel.obs.subscribed(myId)
33+ const mySubs = computed(rawSubs, myChannels => [...myChannels.values()].reverse() )
34+
3235 if (location.scope === "user") {
33- myChannels = subscribed(myId)
34-
35- const mySubscriptions = computed(myChannels, myChannels => [...myChannels.values()])
3636
3737 return h('Page -channelSubscriptions', { title: strings.home }, [
3838 api.app.html.sideNav(location),
3939 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)
40+ when(rawSubs.sync,
41+ [
42+ computed(mySubs, mys => mys.length === 0 ? strings.subscriptions.state.noSubscriptions : ''),
43+ mutantMap(mySubs, api.app.html.channelCard),
44+ ],
45+ h('p', strings.loading)
4946 )
5047 ])
5148 ])
52-
5349 }
5450
5551 if (location.scope === "friends") {
56-
57- myChannels = Value(false)
58-
52+ // update list of other all channels
5953 onceTrue(
6054 api.sbot.obs.connection,
6155 sbot => {
62- sbot.channel.get((err, c) => {
56+ sbot.channel.subscriptions((err, c) => {
6357 if (err) throw err
6458 let b = map(c, (v,k) => {return {channel: k, users: v}})
6559 b = sortBy(b, o => o.users.length)
66- let res = b.reverse().slice(0,100)
60+ let res = b.reverse()
6761
68- myChannels.set(res.map(c => c.channel))
62+ otherChannels.set(res.map(c => c.channel))
6963 })
7064 }
7165 )
7266
67+ const showMoreCounter = Value(1)
68+ const newChannels = computed([otherChannels, mySubs, showMoreCounter], (other, mine, more) => {
69+ return difference(other, mine)
70+ .slice(0, 10*more)
71+ })
7372
74- return h('Page -channelSubscriptions', { title: strings.home }, [
73+ return h('Page -channelSubscriptions', { title: strings.home }, [
7574 api.app.html.sideNav(location),
7675 h('div.content', [
77- when(myChannels,
78- mutantMap(myChannels, api.app.html.channelCard),
79- h("p", strings.loading)
80- )
76+ when(otherChannels,
77+ [
78+ mutantMap(newChannels, api.app.html.channelCard),
79+ h('Button', { 'ev-click': () => showMoreCounter.set(showMoreCounter()+1) },
80+ strings.showMore
81+ )
82+ ],
83+ h('p', strings.loading)
84+ )
8185 ])
8286 ])
8387 }
8488 })
8589 }
8690
8791
88-
89-
app/page/channelSubscriptions.mcssView
@@ -8,13 +8,12 @@
88 div.ChannelCard {
99 border-bottom: 1px solid rgba(0,0,0, .1)
1010 }
1111
12- div {
13- :last-child {
14- padding-bottom: 2rem !important
15- /* TODO fix - eww gross */
16- }
12+ div.Button {
13+ max-width: 20rem
14+
15+ margin: 2rem auto 12rem
1716 }
1817 }
1918 }
2019
app/page/page.mcssView
@@ -22,9 +22,9 @@
2222 margin: 0 auto
2323
2424 div, section {
2525 :last-child {
26- padding-bottom: 6rem !important
26+ /* padding-bottom: 6rem !important */
2727 }
2828 }
2929 }
3030 }
channel/index.jsView
@@ -1,6 +1,9 @@
11 module.exports = {
22 async: require('./async'),
3- obs: require('./obs')
3+ obs: require('./obs'),
4+ html: {
5+ subscribe: require('./html/subscribe')
6+ }
47 }
58
6-
9+
channel/obs.jsView
@@ -9,16 +9,30 @@
99
1010 exports.gives = nest('channel.obs.isSubscribedTo')
1111
1212 exports.create = function (api) {
13+ var subscriptions = {}
14+ var myId
15+
1316 return nest('channel.obs.isSubscribedTo', isSubscribedTo)
1417
1518 function isSubscribedTo (channel, id) {
1619 if (!ref.isFeed(id)) {
17- id = api.keys.sync.id()
20+ id = getMyId()
1821 }
1922
20- const { subscribed } = api.channel.obs
21- const myChannels = subscribed(id)
22- return computed([myChannels], (v) => v.has(channel))
23+ return computed(getSubscriptions(id), (v) => v.has(channel))
2324 }
25+
26+ //cache getters
27+
28+ function getMyId () {
29+ if (!myId) myId = api.keys.sync.id()
30+ return myId
31+ }
32+
33+ function getSubscriptions (id) {
34+ if (!subscriptions[id]) subscriptions[id] = api.channel.obs.subscribed(id)
35+ return subscriptions[id]
36+ }
2437 }
38+
channel/html/subscribe.jsView
@@ -1,0 +1,27 @@
1+const nest = require('depnest')
2+const { h, when } = require('mutant')
3+
4+exports.gives = nest('channel.html.subscribe')
5+
6+exports.needs = nest({
7+ 'keys.sync.id': 'first',
8+ 'translations.sync.strings': 'first',
9+ 'channel.obs.isSubscribedTo': 'first',
10+ 'channel.async.subscribe': 'first',
11+ 'channel.async.unsubscribe': 'first',
12+})
13+
14+exports.create = function (api) {
15+
16+ return nest('channel.html.subscribe', (channel) => {
17+ const strings = api.translations.sync.strings()
18+ const myId = api.keys.sync.id()
19+ const { subscribe, unsubscribe } = api.channel.async
20+
21+ return when(api.channel.obs.isSubscribedTo(channel, myId),
22+ h('Button', { 'ev-click': () => unsubscribe(channel) }, strings.channelShow.action.unsubscribe),
23+ h('Button -primary', { 'ev-click': () => subscribe(channel) }, strings.channelShow.action.subscribe)
24+ )
25+ })
26+}
27+
package.jsonView
@@ -63,9 +63,9 @@
6363 "ssb-private": "^0.1.2",
6464 "ssb-query": "^0.1.2",
6565 "ssb-reduce-stream": "^1.0.2",
6666 "ssb-ref": "^2.7.1",
67- "ssb-server-channel": "^1.0.0",
67+ "ssb-server-channel": "^1.0.2",
6868 "ssb-ws": "^1.0.3",
6969 "suggest-box": "^2.2.3",
7070 "url": "^0.11.0"
7171 },

Built with git-ssb-web