git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit b70759f872a7c4a5c73cc3413f10d221633d860c

get profile feed offset streaming working, show loading state at bottom

Matt McKegg committed on 6/10/2017, 8:55:55 AM
Parent: 407645c2d756a5059346f2bdbc100779f5af7d9e

Files changed

modules/feed/html/rollup.jschanged
modules/feed/pull/summary.jschanged
modules/page/html/render/profile.jschanged
modules/page/html/render/search.jschanged
styles/loading.mcsschanged
modules/feed/html/rollup.jsView
@@ -1,5 +1,6 @@
11 var Value = require('mutant/value')
2+var Proxy = require('mutant/proxy')
23 var when = require('mutant/when')
34 var computed = require('mutant/computed')
45 var h = require('mutant/h')
56 var MutantArray = require('mutant/array')
@@ -37,15 +38,16 @@
3738 return nest({
3839 'feed.html': { rollup }
3940 })
4041 function rollup (getStream, opts) {
41- var sync = Value(false)
42+ var loading = Proxy(true)
4243 var updates = Value(0)
4344
4445 var filter = opts && opts.filter
4546 var bumpFilter = opts && opts.bumpFilter
4647 var windowSize = opts && opts.windowSize
4748 var waitFor = opts && opts.waitFor || true
49+ var getSequence = opts && opts.getSequence
4850
4951 var newSinceRefresh = new Set()
5052 var newInSession = new Set()
5153 var prioritized = {}
@@ -65,10 +67,10 @@
6567 style: { overflow: 'auto' }
6668 }, [
6769 h('div.wrapper', [
6870 h('section.prepend', opts.prepend),
69- when(sync, null, h('Loading -large')),
70- content
71+ content,
72+ when(loading, h('Loading -large'))
7173 ])
7274 ])
7375
7476 onceTrue(waitFor, () => {
@@ -136,14 +138,11 @@
136138 if (abortLastFeed) {
137139 abortLastFeed()
138140 }
139141 updates.set(0)
140- sync.set(false)
141142
142143 content.set(
143- h('section.content', {
144- hidden: computed(sync, s => !s)
145- })
144+ h('section.content')
146145 )
147146
148147 var abortable = Abortable()
149148 abortLastFeed = abortable.abort
@@ -152,12 +151,13 @@
152151 newSinceRefresh.forEach(x => {
153152 prioritized[x] = 2
154153 })
155154
155+ var stream = api.feed.pull.summary(getStream, {windowSize, bumpFilter, prioritized, getSequence})
156+ loading.set(stream.loading)
157+
156158 pull(
157- api.feed.pull.summary(getStream, {windowSize, bumpFilter, prioritized}, () => {
158- sync.set(true)
159- }),
159+ stream,
160160 pull.asyncMap(ensureMessageAndAuthor),
161161 pull.filter((item) => {
162162 // ignore messages that are handled by other apps
163163 if (item.rootMessage && api.app.sync.externalHandler(item.rootMessage)) return
modules/feed/pull/summary.jsView
@@ -3,8 +3,10 @@
33 var pullNext = require('pull-next')
44 var SortedArray = require('sorted-array-functions')
55 var nest = require('depnest')
66 var ref = require('ssb-ref')
7+var sustained = require('../../../lib/sustained')
8+var Value = require('mutant/value')
79
810 exports.gives = nest({
911 'feed.pull': [ 'summary' ]
1012 })
@@ -18,21 +20,28 @@
1820 function summary (source, opts, cb) {
1921 var bumpFilter = opts && opts.bumpFilter
2022 var windowSize = opts && opts.windowSize || 1000
2123 var prioritized = opts && opts.prioritized || {}
24+ var getSequence = opts && opts.getSequence
25+
26+ var loading = Value(true)
27+
2228 var last = null
2329 var returned = false
2430 var done = false
25- return pullNext(() => {
31+
32+ var result = pullNext(() => {
2633 if (!done) {
34+ loading.set(true)
2735 var next = {reverse: true, limit: windowSize, live: false}
2836 if (last) {
29- next.lt = last.timestamp || last.value.sequence
37+ next.lt = typeof getSequence === 'function' ? getSequence(last) : last.timestamp
3038 }
3139 var deferred = pullDefer.source()
3240 pull(
3341 source(next),
3442 pull.collect((err, values) => {
43+ loading.set(false)
3544 if (err) throw err
3645 if (!values.length) {
3746 done = true
3847 deferred.resolve(pull.values([]))
@@ -54,8 +63,13 @@
5463 )
5564 }
5665 return deferred
5766 })
67+
68+ // switch to loading state immediately, only revert after no loading for > 200 ms
69+ result.loading = sustained(loading, 500, x => x)
70+
71+ return result
5872 }
5973
6074 function groupMessages (messages, fromTime, opts, cb) {
6175 var subscribes = {}
modules/page/html/render/profile.jsView
@@ -166,9 +166,9 @@
166166 ])
167167
168168 var feedView = api.feed.html.rollup((opts) => {
169169 return api.sbot.pull.userFeed(extend(opts, {id}))
170- }, { prepend })
170+ }, { prepend, getSequence: x => x.value.sequence })
171171
172172 var container = h('div', {className: 'SplitView'}, [
173173 h('div.main', [
174174 feedView
modules/page/html/render/search.jsView
@@ -266,9 +266,8 @@
266266 cb(true)
267267 } else {
268268 setTimeout(() => {
269269 cb(true)
270- console.log('delay')
271270 }, delay)
272271 }
273272 }
274273 }
styles/loading.mcssView
@@ -1,6 +1,6 @@
11 Loading {
2- height: 25%
2+ height: 25vh
33 display: flex
44 align-items: center
55 justify-content: center
66

Built with git-ssb-web