git ssb

2+

mixmix / ticktack



Commit 8cd7bb64a48c38cc0162aa1de3f8969e22670e27

explore ordering by time in blogIndex

mix committed on 1/24/2018, 4:07:23 AM
Parent: 9eabddbe35e54d91464df1db3938434a29c56474

Files changed

app/page/blogIndex.jschanged
app/page/blogIndex.jsView
@@ -1,15 +1,15 @@
11 const nest = require('depnest')
2-const { h } = require('mutant')
2+const { h, Value, resolve } = require('mutant')
33 const pull = require('pull-stream')
44
55 exports.gives = nest('app.page.blogIndex')
66
77 exports.needs = nest({
8- 'app.html.sideNav': 'first',
98 'app.html.blogCard': 'first',
109 'app.html.blogNav': 'first',
1110 'app.html.scroller': 'first',
11+ 'app.html.sideNav': 'first',
1212 // 'feed.pull.public': 'first',
1313 'feed.pull.type': 'first',
1414 'history.sync.push': 'first',
1515 'keys.sync.id': 'first',
@@ -39,10 +39,10 @@
3939 ),
4040 // FUTURE : if we need better perf, we can add a persistent cache. At the moment this page is fast enough though.
4141 // See implementation of app.html.sideNav for example
4242 // store: recentMsgCache,
43- // updateTop: updateRecentMsgCache,
44- // updateBottom: updateRecentMsgCache,
43+ updateTop: update,
44+ updateBottom: update,
4545 render
4646 })
4747
4848 return h('Page -blogIndex', {title: strings.home}, [
@@ -51,9 +51,30 @@
5151 ])
5252 })
5353
5454
55+ function update (soFar, newBlog) {
56+ soFar.transaction(() => {
57+ const { timestamp } = newBlog.value
5558
59+ var object = newBlog // Value(newBlog)
60+
61+ // Orders by: time received
62+ const justOlderPosition = indexOf(soFar, (msg) => newBlog.timestamp > resolve(msg).timestamp)
63+
64+ // Orders by: time published BUT the messagesByType stream streams _by time received_
65+ // TODO - we need an index of all blogs otherwise the scroller doesn't work...
66+ // const justOlderPosition = indexOf(soFar, (msg) => timestamp > resolve(msg).value.timestamp)
67+
68+ if (justOlderPosition > -1) {
69+ soFar.insert(object, justOlderPosition)
70+ } else {
71+ soFar.push(object)
72+ }
73+ })
74+ }
75+
76+
5677 function render (blog) {
5778 const { recps, channel } = blog.value.content
5879 var onClick
5980 if (channel && !recps)
@@ -61,7 +82,13 @@
6182 return api.app.html.blogCard(blog, { onClick })
6283 }
6384 }
6485
86+function indexOf (array, fn) {
87+ for (var i = 0; i < array.getLength(); i++) {
88+ if (fn(array.get(i))) {
89+ return i
90+ }
91+ }
92+ return -1
93+}
6594
66-
67-

Built with git-ssb-web