Commit 17df3c936c4c4573ec97072a96be633ed3ae1c2b
wip
mix irving committed on 5/19/2018, 6:33:09 AMParent: c0dd626b0d708d6baff34a5f1e8fb399bc0119cd
Files changed
app/page/blogIndex.js | changed |
app/page/blogIndex.js | ||
---|---|---|
@@ -1,14 +1,16 @@ | ||
1 | 1 … | const nest = require('depnest') |
2 | 2 … | const { h, Value, Array: MutantArray, resolve } = require('mutant') |
3 … | +const Scroller = require('mutant-scroll') | |
3 | 4 … | const pull = require('pull-stream') |
5 … | +const Next = require('pull-next') | |
4 | 6 … | |
5 | 7 … | exports.gives = nest('app.page.blogIndex') |
6 | 8 … | |
7 | 9 … | exports.needs = nest({ |
8 | 10 … | 'app.html.blogCard': 'first', |
9 | 11 … | 'app.html.topNav': 'first', |
10 | - 'app.html.scroller': 'first', | |
12 … | + // 'app.html.scroller': 'first', | |
11 | 13 … | 'app.html.sideNav': 'first', |
12 | 14 … | 'blog.sync.isBlog': 'first', |
13 | 15 … | 'feed.pull.public': 'first', |
14 | 16 … | 'feed.pull.type': 'first', |
@@ -26,23 +28,38 @@ | ||
26 | 28 … | // location here can expected to be: { page: 'blogIndex'} |
27 | 29 … | |
28 | 30 … | var strings = api.translations.sync.strings() |
29 | 31 … | |
30 | - var blogs = api.app.html.scroller({ | |
32 … | + // const filter = () => pull( | |
33 … | + // pull.filter(api.blog.sync.isBlog), // isBlog or Plog? | |
34 … | + // pull.filter(msg => !msg.value.content.root), // show only root messages | |
35 … | + // pull.filter(msg => !api.message.sync.isBlocked(msg)) // this is already in feed.pull.type | |
36 … | + // ) | |
37 … | + | |
38 … | + // stream: api.feed.pull.public, // for post + blog type | |
39 … | + | |
40 … | + const streamToTop = pull( | |
41 … | + // next(stream, { live: true, reverse: false, old: false, limit: 100, property: indexProperty }), | |
42 … | + api.feed.pull.type('blog')({ live: true, reverse: false, old: false }), | |
43 … | + // filter() | |
44 … | + ) | |
45 … | + | |
46 … | + | |
47 … | + const streamToBottom = pull( | |
48 … | + Next | |
49 … | + api.feed.pull.type('blog')({ live: false, reverse: true }), | |
50 … | + // filter() | |
51 … | + | |
52 … | + ) | |
53 … | + | |
54 … | + var blogs = Scroller({ | |
31 | 55 … | classList: ['content'], |
32 | 56 … | prepend: api.app.html.topNav(location), |
33 | - // stream: api.feed.pull.public, | |
34 | - stream: api.feed.pull.type('blog'), | |
35 | - filter: () => pull( | |
36 | - // pull.filter(api.blog.sync.isBlog), | |
37 | - pull.filter(msg => !msg.value.content.root), // show only root messages | |
38 | - pull.filter(msg => !api.message.sync.isBlocked(msg)) | |
39 | - ), | |
40 | - // FUTURE : if we need better perf, we can add a persistent cache. At the moment this page is fast enough though. | |
41 | - // See implementation of app.html.sideNav for example | |
42 | - store: blogsCache, | |
57 … | + streamToTop, | |
58 … | + streamToBottom, | |
43 | 59 … | updateTop: update, |
44 | 60 … | updateBottom: update, |
61 … | + store: blogsCache, | |
45 | 62 … | render |
46 | 63 … | }) |
47 | 64 … | |
48 | 65 … | return h('Page -blogIndex', {title: strings.home}, [ |
@@ -52,10 +69,8 @@ | ||
52 | 69 … | }) |
53 | 70 … | |
54 | 71 … | function update (soFar, newBlog) { |
55 | 72 … | soFar.transaction(() => { |
56 | - const { timestamp } = newBlog.value | |
57 | - | |
58 | 73 … | var object = newBlog // Value(newBlog) |
59 | 74 … | |
60 | 75 … | const index = indexOf(soFar, (blog) => newBlog.key === resolve(blog).key) |
61 | 76 … | // if blog already in cache, not needed again |
@@ -65,9 +80,9 @@ | ||
65 | 80 … | const justOlderPosition = indexOf(soFar, (msg) => newBlog.timestamp > resolve(msg).timestamp) |
66 | 81 … | |
67 | 82 … | // Orders by: time published BUT the messagesByType stream streams _by time received_ |
68 | 83 … | // TODO - we need an index of all blogs otherwise the scroller doesn't work... |
69 | - // const justOlderPosition = indexOf(soFar, (msg) => timestamp > resolve(msg).value.timestamp) | |
84 … | + // const justOlderPosition = indexOf(soFar, (msg) => newBlog.value.timestamp > resolve(msg).value.timestamp) | |
70 | 85 … | |
71 | 86 … | if (justOlderPosition > -1) { |
72 | 87 … | soFar.insert(object, justOlderPosition) |
73 | 88 … | } else { |
Built with git-ssb-web