Commit d01f8cc07bc8311ed0717219f766c6a4dd7cec7a
make search page, refactor mutant-scroll a little
mix irving committed on 11/30/2017, 2:13:28 AMParent: e521f4fb1c6acfda5614b65c29e094159a72a2b6
Files changed
app/html/app.mcss | changed |
app/html/blogHeader.js | changed |
app/html/header.js | changed |
app/index.js | changed |
app/page/blogIndex.mcss | changed |
app/page/blogSearch.js | added |
app/page/blogSearch.mcss | added |
package-lock.json | changed |
package.json | changed |
router/sync/routes.js | changed |
app/html/app.mcss | ||
---|---|---|
@@ -1,7 +1,7 @@ | ||
1 | 1 | App { |
2 | 2 | overflow: hidden |
3 | - position: absolute | |
3 | + position: fixed | |
4 | 4 | top: 0 |
5 | 5 | bottom: 0 |
6 | 6 | right: 0 |
7 | 7 | left: 0 |
app/html/blogHeader.js | ||
---|---|---|
@@ -13,17 +13,17 @@ | ||
13 | 13 | return nest('app.html.blogHeader', (location) => { |
14 | 14 | const strings = api.translations.sync.strings() |
15 | 15 | const goTo = (loc) => () => api.history.sync.push(loc) |
16 | 16 | |
17 | - if (location.page === 'blogIndex') { | |
17 | + if (location.page === 'blogIndex' || location.page === 'blogSearch') { | |
18 | 18 | return h('BlogHeader', [ |
19 | 19 | h('div.left', [ |
20 | 20 | h('div', { |
21 | 21 | className: location.page === 'blogIndex' ? '-active' : '', |
22 | 22 | 'ev-click': goTo({ page: 'blogIndex' }) |
23 | 23 | }, strings.blogHeader.blogsAll), |
24 | 24 | h('div', { |
25 | - className: location.page === 'blogSearch' ? 'active' : '', | |
25 | + className: location.page === 'blogSearch' ? '-active' : '', | |
26 | 26 | 'ev-click': goTo({ page: 'blogSearch' }) |
27 | 27 | }, strings.blogHeader.blogSearch), |
28 | 28 | ]), |
29 | 29 | h('div.right', [ |
app/html/header.js | ||
---|---|---|
@@ -5,15 +5,8 @@ | ||
5 | 5 | exports.gives = nest('app.html.header') |
6 | 6 | |
7 | 7 | exports.needs = nest('keys.sync.id', 'first') |
8 | 8 | |
9 | -const FEED_PAGES = [ | |
10 | - 'blogIndex', | |
11 | - 'blogNew', | |
12 | - 'threadShow', // TODO - this doesn't work (`threadSHow` isn't part of the location atm) | |
13 | - 'threadNew', | |
14 | - // 'blogSearch', | |
15 | -] | |
16 | 9 | const SETTINGS_PAGES = [ |
17 | 10 | 'settings', |
18 | 11 | 'userEdit', |
19 | 12 | ] |
@@ -27,16 +20,14 @@ | ||
27 | 20 | |
28 | 21 | return location || {} |
29 | 22 | }) |
30 | 23 | |
31 | - const isFeed = computed(loc, loc => { | |
32 | - return FEED_PAGES.includes(loc.page) || (loc.key && loc.feed) | |
33 | - }) | |
34 | - | |
35 | 24 | const isSettings = computed(loc, loc => { |
36 | 25 | return SETTINGS_PAGES.includes(loc.page) |
37 | 26 | }) |
38 | 27 | |
28 | + const isFeed = computed([isSettings], isSettings => !isSettings) | |
29 | + | |
39 | 30 | return h('Header', [ |
40 | 31 | h('nav', [ |
41 | 32 | h('i.fa', { |
42 | 33 | 'ev-click': () => push({page: 'blogIndex'}), |
app/index.js | ||
---|---|---|
@@ -15,8 +15,9 @@ | ||
15 | 15 | }, |
16 | 16 | page: { |
17 | 17 | blogIndex: require('./page/blogIndex'), |
18 | 18 | blogNew: require('./page/blogNew'), |
19 | + blogSearch: require('./page/blogSearch'), | |
19 | 20 | blogShow: require('./page/blogShow'), |
20 | 21 | error: require('./page/error'), |
21 | 22 | settings: require('./page/settings'), |
22 | 23 | // channel: require('./page/channel'), |
app/page/blogIndex.mcss | ||
---|---|---|
@@ -1,38 +1,30 @@ | ||
1 | 1 | Page -blogIndex { |
2 | 2 | div.content { padding: 0 } |
3 | 3 | |
4 | 4 | div.Scroller.content { |
5 | + section.top { | |
6 | + position: sticky | |
7 | + left: 0 | |
8 | + right: 0 | |
9 | + top: 0 | |
10 | + } | |
5 | 11 | |
6 | - div.wrapper { | |
7 | - display: flex | |
8 | - flex-wrap: wrap | |
9 | - justify-content: center | |
12 | + section.content { | |
13 | + background-color: #fff | |
14 | + $maxWidth | |
15 | + margin: .8rem | |
16 | + padding: 0 2rem | |
10 | 17 | |
11 | - section.top { | |
12 | - position: sticky | |
13 | - left: 0 | |
14 | - right: 0 | |
15 | - top: 0 | |
16 | - flex-basis: 100% | |
18 | + div.BlogCard { | |
19 | + border-bottom: 1px solid gainsboro | |
17 | 20 | } |
21 | + } | |
18 | 22 | |
19 | - section.content { | |
20 | - background-color: #fff | |
21 | - $maxWidth | |
22 | - margin: .8rem | |
23 | - padding: 0 2rem | |
24 | - | |
25 | - div.BlogCard { | |
26 | - border-bottom: 1px solid gainsboro | |
27 | - } | |
23 | + section.bottom { | |
24 | + div.Button { | |
25 | + margin: 1rem 0 | |
28 | 26 | } |
29 | - | |
30 | - section.bottom { | |
31 | - div.Button { | |
32 | - margin: 1rem 0 | |
33 | - } | |
34 | - } | |
35 | 27 | } |
36 | 28 | } |
37 | 29 | } |
38 | 30 |
app/page/blogSearch.js | ||
---|---|---|
@@ -1,0 +1,63 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { h } = require('mutant') | |
3 | +const pull = require('pull-stream') | |
4 | + | |
5 | +exports.gives = nest('app.page.blogSearch') | |
6 | + | |
7 | +exports.needs = nest({ | |
8 | + 'app.html.context': 'first', | |
9 | + 'app.html.blogCard': 'first', | |
10 | + 'app.html.blogHeader': 'first', | |
11 | + 'app.html.scroller': 'first', | |
12 | + 'feed.pull.public': 'first', | |
13 | + 'history.sync.push': 'first', | |
14 | + 'keys.sync.id': 'first', | |
15 | + 'translations.sync.strings': 'first', | |
16 | + 'unread.sync.isUnread': 'first' | |
17 | +}) | |
18 | + | |
19 | +exports.create = (api) => { | |
20 | + return nest('app.page.blogSearch', blogSearch) | |
21 | + | |
22 | + function blogSearch (location) { | |
23 | + // location here can expected to be: { page: 'blogSearch'} | |
24 | + | |
25 | + var strings = api.translations.sync.strings() | |
26 | + | |
27 | + var blogs = api.app.html.scroller({ | |
28 | + classList: ['content'], | |
29 | + prepend: api.app.html.blogHeader(location), | |
30 | + stream: api.feed.pull.public, | |
31 | + filter: () => pull( | |
32 | + pull.filter(msg => { | |
33 | + const type = msg.value.content.type | |
34 | + return type === 'post' || type === 'blog' | |
35 | + }), | |
36 | + pull.filter(msg => !msg.value.content.root) // show only root messages | |
37 | + ), | |
38 | + // FUTURE : if we need better perf, we can add a persistent cache. At the moment this page is fast enough though. | |
39 | + // See implementation of app.html.context for example | |
40 | + // store: recentMsgCache, | |
41 | + // updateTop: updateRecentMsgCache, | |
42 | + // updateBottom: updateRecentMsgCache, | |
43 | + render | |
44 | + }) | |
45 | + | |
46 | + return h('Page -blogSearch', {title: strings.home}, [ | |
47 | + api.app.html.context(location), | |
48 | + blogs | |
49 | + ]) | |
50 | + } | |
51 | + | |
52 | + | |
53 | + function render (blog) { | |
54 | + const { recps, channel } = blog.value.content | |
55 | + var onClick | |
56 | + if (channel && !recps) | |
57 | + onClick = (ev) => api.history.sync.push(Object.assign({}, blog, { page: 'blogShow' })) | |
58 | + | |
59 | + return api.app.html.blogCard(blog, { onClick }) | |
60 | + } | |
61 | +} | |
62 | + | |
63 | + |
app/page/blogSearch.mcss | ||
---|---|---|
@@ -1,0 +1,32 @@ | ||
1 | +Page -blogSearch { | |
2 | + div.content { padding: 0 } | |
3 | + | |
4 | + div.Scroller.content { | |
5 | + section.top { | |
6 | + position: sticky | |
7 | + left: 0 | |
8 | + right: 0 | |
9 | + top: 0 | |
10 | + flex-basis: 100% | |
11 | + } | |
12 | + | |
13 | + section.content { | |
14 | + background-color: #fff | |
15 | + $maxWidth | |
16 | + margin: .8rem | |
17 | + padding: 0 2rem | |
18 | + | |
19 | + div.BlogCard { | |
20 | + border-bottom: 1px solid gainsboro | |
21 | + } | |
22 | + } | |
23 | + | |
24 | + section.bottom { | |
25 | + div.Button { | |
26 | + margin: 1rem 0 | |
27 | + } | |
28 | + } | |
29 | + } | |
30 | +} | |
31 | + | |
32 | + |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 211063 bytes New file size: 211063 bytes |
package.json | ||
---|---|---|
@@ -34,9 +34,9 @@ | ||
34 | 34 | "markdown-summary": "^1.0.3", |
35 | 35 | "micro-css": "^2.0.1", |
36 | 36 | "morphdom": "^2.3.3", |
37 | 37 | "mutant": "^3.21.2", |
38 | - "mutant-scroll": "0.0.3", | |
38 | + "mutant-scroll": "0.0.4", | |
39 | 39 | "open-external": "^0.1.1", |
40 | 40 | "patch-history": "^1.0.0", |
41 | 41 | "patch-profile": "^1.0.2", |
42 | 42 | "patch-settings": "^1.0.0", |
router/sync/routes.js | ||
---|---|---|
@@ -8,8 +8,9 @@ | ||
8 | 8 | exports.needs = nest({ |
9 | 9 | 'app.page.error': 'first', |
10 | 10 | 'app.page.blogIndex': 'first', |
11 | 11 | 'app.page.blogNew': 'first', |
12 | + 'app.page.blogSearch': 'first', | |
12 | 13 | 'app.page.blogShow': 'first', |
13 | 14 | 'app.page.settings': 'first', |
14 | 15 | // 'app.page.channel': 'first', |
15 | 16 | // 'app.page.groupFind': 'first', |
@@ -34,8 +35,9 @@ | ||
34 | 35 | |
35 | 36 | // Blog pages |
36 | 37 | [ location => location.page === 'blogIndex', pages.blogIndex ], |
37 | 38 | [ location => location.page === 'blogNew', pages.blogNew ], |
39 | + [ location => location.page === 'blogSearch', pages.blogSearch ], | |
38 | 40 | [ location => location.page === 'blogShow', pages.blogShow ], |
39 | 41 | [ location => isMsg(location.key) && get(location, 'value.content.type') === 'blog', pages.blogShow ], |
40 | 42 | [ location => { |
41 | 43 | return isMsg(location.key) |
Built with git-ssb-web