Commit 8cd7bb64a48c38cc0162aa1de3f8969e22670e27
explore ordering by time in blogIndex
mix committed on 1/24/2018, 4:07:23 AMParent: 9eabddbe35e54d91464df1db3938434a29c56474
Files changed
app/page/blogIndex.js | changed |
app/page/blogIndex.js | ||
---|---|---|
@@ -1,15 +1,15 @@ | ||
1 | 1 | const nest = require('depnest') |
2 | -const { h } = require('mutant') | |
2 | +const { h, Value, resolve } = require('mutant') | |
3 | 3 | const pull = require('pull-stream') |
4 | 4 | |
5 | 5 | exports.gives = nest('app.page.blogIndex') |
6 | 6 | |
7 | 7 | exports.needs = nest({ |
8 | - 'app.html.sideNav': 'first', | |
9 | 8 | 'app.html.blogCard': 'first', |
10 | 9 | 'app.html.blogNav': 'first', |
11 | 10 | 'app.html.scroller': 'first', |
11 | + 'app.html.sideNav': 'first', | |
12 | 12 | // 'feed.pull.public': 'first', |
13 | 13 | 'feed.pull.type': 'first', |
14 | 14 | 'history.sync.push': 'first', |
15 | 15 | 'keys.sync.id': 'first', |
@@ -39,10 +39,10 @@ | ||
39 | 39 | ), |
40 | 40 | // FUTURE : if we need better perf, we can add a persistent cache. At the moment this page is fast enough though. |
41 | 41 | // See implementation of app.html.sideNav for example |
42 | 42 | // store: recentMsgCache, |
43 | - // updateTop: updateRecentMsgCache, | |
44 | - // updateBottom: updateRecentMsgCache, | |
43 | + updateTop: update, | |
44 | + updateBottom: update, | |
45 | 45 | render |
46 | 46 | }) |
47 | 47 | |
48 | 48 | return h('Page -blogIndex', {title: strings.home}, [ |
@@ -51,9 +51,30 @@ | ||
51 | 51 | ]) |
52 | 52 | }) |
53 | 53 | |
54 | 54 | |
55 | + function update (soFar, newBlog) { | |
56 | + soFar.transaction(() => { | |
57 | + const { timestamp } = newBlog.value | |
55 | 58 | |
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 | + | |
56 | 77 | function render (blog) { |
57 | 78 | const { recps, channel } = blog.value.content |
58 | 79 | var onClick |
59 | 80 | if (channel && !recps) |
@@ -61,7 +82,13 @@ | ||
61 | 82 | return api.app.html.blogCard(blog, { onClick }) |
62 | 83 | } |
63 | 84 | } |
64 | 85 | |
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 | +} | |
65 | 94 | |
66 | - | |
67 | - |
Built with git-ssb-web