Commit e73bff8390f085ab1944c5d9ac4c514cbbacf355
first pass navigation
mix irving committed on 8/9/2017, 5:57:07 AMParent: ca60633113df0b41f3bab3e4319dcd13a9c9555e
Files changed
app/html/app.js | changed |
app/html/thread.js | changed |
app/html/nav.js | added |
app/html/nav.mcss | added |
app/index.js | changed |
app/page/group.js | changed |
app/page/home.js | changed |
app/page/page.mcss | changed |
app/page/private.js | changed |
app/sync/goTo.js | deleted |
index.js | changed |
history/index.js | added |
history/obs/store.js | added |
history/sync/back.js | added |
history/sync/push.js | added |
app/html/app.js | ||
---|---|---|
@@ -4,9 +4,9 @@ | ||
4 | 4 | |
5 | 5 | exports.gives = nest('app.html.app') |
6 | 6 | |
7 | 7 | exports.needs = nest({ |
8 | - 'app.sync.goTo': 'first', | |
8 | + 'history.sync.push': 'first', | |
9 | 9 | 'styles.css': 'first' |
10 | 10 | }) |
11 | 11 | |
12 | 12 | exports.create = (api) => { |
@@ -15,7 +15,7 @@ | ||
15 | 15 | function app () { |
16 | 16 | const css = values(api.styles.css()).join('\n') |
17 | 17 | insertCss(css) |
18 | 18 | |
19 | - return api.app.sync.goTo({ page: 'home' }) | |
19 | + return api.history.sync.push({ page: 'home' }) | |
20 | 20 | } |
21 | 21 | } |
app/html/thread.js | ||
---|---|---|
@@ -7,9 +7,8 @@ | ||
7 | 7 | exports.gives = nest('app.html.thread') |
8 | 8 | |
9 | 9 | exports.needs = nest({ |
10 | 10 | 'about.html.image': 'first', |
11 | - 'app.sync.goTo': 'first', | |
12 | 11 | 'feed.obs.thread': 'first', |
13 | 12 | 'keys.sync.id': 'first', |
14 | 13 | 'message.html.markdown': 'first' |
15 | 14 | }) |
@@ -25,9 +24,8 @@ | ||
25 | 24 | |
26 | 25 | const thread = api.feed.obs.thread(id) |
27 | 26 | const chunkedMessages = buildChunkedMessages(thread.messages) |
28 | 27 | |
29 | - const { goTo } = api.app.sync | |
30 | 28 | const threadView = h('Thread', |
31 | 29 | map(chunkedMessages, chunk => { |
32 | 30 | const author = computed([chunk], chunk => get(chunk, '[0].value.author')) |
33 | 31 |
app/html/nav.js | ||
---|---|---|
@@ -1,0 +1,25 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { h } = require('mutant') | |
3 | + | |
4 | +exports.gives = nest('app.html.nav') | |
5 | + | |
6 | +exports.needs = nest({ | |
7 | + 'history.sync.push': 'first', | |
8 | + 'history.sync.back': 'first' | |
9 | +}) | |
10 | + | |
11 | +exports.create = (api) => { | |
12 | + return nest('app.html.nav', nav) | |
13 | + | |
14 | + function nav (id) { | |
15 | + const { push, back } = api.history.sync | |
16 | + return h('Nav', [ | |
17 | + h('div', { 'ev-click': back }, '(<)'), | |
18 | + h('div', { 'ev-click': () => push({page: 'home'}) }, 'Home'), | |
19 | + h('div', { 'ev-click': () => push({type: 'group', key: '%sadlkjas;lkdjas'}) }, 'Group'), | |
20 | + h('div', { 'ev-click': () => push({key: '%fXXZgQrwnj7F+Y19H0IXxNriuvPFoahvusih3UzpkfA=.sha256'}) }, 'Private Thread A'), | |
21 | + h('div', { 'ev-click': () => push({key: '%3cWZHeN6k03XpvDBxrxP5bGLsNByFLTvr/rKYFV4f+c=.sha256'}) }, 'Private Thread B'), | |
22 | + ]) | |
23 | + } | |
24 | +} | |
25 | + |
app/html/nav.mcss | ||
---|---|---|
@@ -1,0 +1,11 @@ | ||
1 | +Nav { | |
2 | + display: flex | |
3 | + margin-left: 1rem | |
4 | + | |
5 | + div { | |
6 | + margin-right: 1rem | |
7 | + | |
8 | + | |
9 | + } | |
10 | +} | |
11 | + |
app/index.js | ||
---|---|---|
@@ -1,14 +1,12 @@ | ||
1 | 1 | module.exports = { |
2 | 2 | html: { |
3 | 3 | app: require('./html/app'), |
4 | - thread: require('./html/thread') | |
4 | + thread: require('./html/thread'), | |
5 | + nav: require('./html/nav') | |
5 | 6 | }, |
6 | 7 | page: { |
7 | 8 | group: require('./page/group'), |
8 | 9 | home: require('./page/home'), |
9 | 10 | private: require('./page/private') |
10 | - }, | |
11 | - sync: { | |
12 | - goTo: require('./sync/goTo') | |
13 | 11 | } |
14 | 12 | } |
app/page/group.js | ||
---|---|---|
@@ -3,9 +3,9 @@ | ||
3 | 3 | |
4 | 4 | exports.gives = nest('app.page.group') |
5 | 5 | |
6 | 6 | exports.needs = nest({ |
7 | - 'app.sync.goTo': 'first' | |
7 | + 'app.html.nav': 'first' | |
8 | 8 | }) |
9 | 9 | |
10 | 10 | exports.create = (api) => { |
11 | 11 | return nest('app.page.group', group) |
@@ -17,9 +17,9 @@ | ||
17 | 17 | const { goTo } = api.app.sync |
18 | 18 | |
19 | 19 | return h('Page -group', [ |
20 | 20 | h('h1', 'Group'), |
21 | - h('a', { 'ev-click': () => goTo({ page: 'home' }) }, 'Home'), | |
21 | + api.app.html.nav(), | |
22 | 22 | h('p', `key: ${location.key}`) |
23 | 23 | ]) |
24 | 24 | } |
25 | 25 | } |
app/page/home.js | ||
---|---|---|
@@ -3,25 +3,19 @@ | ||
3 | 3 | |
4 | 4 | exports.gives = nest('app.page.home') |
5 | 5 | |
6 | 6 | exports.needs = nest({ |
7 | - 'app.sync.goTo': 'first' | |
7 | + 'app.html.nav': 'first' | |
8 | 8 | }) |
9 | 9 | |
10 | 10 | exports.create = (api) => { |
11 | 11 | return nest('app.page.home', home) |
12 | 12 | |
13 | 13 | function home (location) { |
14 | 14 | // location here can expected to be: { page: 'home' } |
15 | - const { goTo } = api.app.sync | |
16 | 15 | |
17 | 16 | return h('Page -home', [ |
18 | 17 | h('h1', 'Home'), |
19 | - h('nav', [ | |
20 | - h('div', { 'ev-click': () => goTo({ page: 'home' }) }, 'Home'), | |
21 | - h('div', { 'ev-click': () => goTo({ type: 'group', key: '%sadlkjas;lkdjas' }) }, 'Group'), | |
22 | - h('div', { 'ev-click': () => goTo({key: '%fXXZgQrwnj7F+Y19H0IXxNriuvPFoahvusih3UzpkfA=.sha256'}) }, 'Private Thread A'), | |
23 | - h('div', { 'ev-click': () => goTo({key: '%3cWZHeN6k03XpvDBxrxP5bGLsNByFLTvr/rKYFV4f+c=.sha256'}) }, 'Private Thread B'), | |
24 | - ]) | |
18 | + api.app.html.nav(), | |
25 | 19 | ]) |
26 | 20 | } |
27 | 21 | } |
app/page/private.js | ||
---|---|---|
@@ -5,24 +5,23 @@ | ||
5 | 5 | |
6 | 6 | exports.gives = nest('app.page.private') |
7 | 7 | |
8 | 8 | exports.needs = nest({ |
9 | - 'app.sync.goTo': 'first', | |
9 | + 'app.html.nav': 'first', | |
10 | 10 | 'app.html.thread': 'first' |
11 | 11 | }) |
12 | 12 | |
13 | 13 | exports.create = (api) => { |
14 | 14 | return nest('app.page.private', private) |
15 | 15 | |
16 | 16 | function private (location) { |
17 | 17 | // location here can expected to be an ssb-message |
18 | - const { goTo } = api.app.sync | |
19 | 18 | |
20 | 19 | const thread = api.app.html.thread(location.key) |
21 | 20 | |
22 | 21 | return h('Page -private', [ |
23 | 22 | h('h1', 'Private message'), |
24 | - h('nav', { 'ev-click': () => goTo({ page: 'home' }) }, 'Home'), | |
23 | + api.app.html.nav(), | |
25 | 24 | thread |
26 | 25 | ]) |
27 | 26 | } |
28 | 27 | } |
app/sync/goTo.js | ||
---|---|---|
@@ -1,22 +1,0 @@ | ||
1 | -const nest = require('depnest') | |
2 | - | |
3 | -exports.gives = nest('app.sync.goTo') | |
4 | - | |
5 | -exports.needs = nest({ | |
6 | - 'router.sync.router': 'first' | |
7 | -}) | |
8 | - | |
9 | -exports.create = (api) => { | |
10 | - return nest('app.sync.goTo', goTo) | |
11 | - | |
12 | - function goTo (location) { | |
13 | - console.log('goTo', location) | |
14 | - const newView = api.router.sync.router(location) | |
15 | - | |
16 | - // TODO (mix) : change once history in place | |
17 | - const oldView = document.body.firstChild | |
18 | - oldView | |
19 | - ? document.body.replaceChild(newView, oldView) | |
20 | - : document.body.appendChild(newView) | |
21 | - } | |
22 | -} |
index.js | ||
---|---|---|
@@ -1,7 +1,8 @@ | ||
1 | 1 | const ticktack = { |
2 | 2 | app: require('./app'), |
3 | 3 | blob: require('./blob'), |
4 | + history: require('./history'), | |
4 | 5 | router: require('./router'), |
5 | 6 | styles: require('./styles') |
6 | 7 | } |
7 | 8 |
history/index.js | ||
---|---|---|
@@ -1,0 +1,10 @@ | ||
1 | +module.exports ={ | |
2 | + obs: { | |
3 | + store: require('./obs/store'), | |
4 | + }, | |
5 | + sync: { | |
6 | + push: require('./sync/push'), | |
7 | + back: require('./sync/back') | |
8 | + } | |
9 | +} | |
10 | + |
history/obs/store.js | ||
---|---|---|
@@ -1,0 +1,11 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { Array: MutantArray } = require('mutant') | |
3 | + | |
4 | +exports.gives = nest('history.obs.store') | |
5 | + | |
6 | +var _store = MutantArray() | |
7 | + | |
8 | +exports.create = (api) => { | |
9 | + return nest('history.obs.store', () => _store) | |
10 | +} | |
11 | + |
history/sync/back.js | ||
---|---|---|
@@ -1,0 +1,31 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const last = require('lodash/last') | |
3 | + | |
4 | +exports.gives = nest('history.sync.back') | |
5 | + | |
6 | +exports.needs = nest({ | |
7 | + 'history.obs.store': 'first', | |
8 | + 'router.sync.router': 'first' | |
9 | +}) | |
10 | + | |
11 | +exports.create = (api) => { | |
12 | + return nest('history.sync.back', back) | |
13 | + | |
14 | + function back () { | |
15 | + const history = api.history.obs.store() | |
16 | + if (history().length === 1) return false | |
17 | + | |
18 | + history.pop() | |
19 | + const location = last(history()) | |
20 | + | |
21 | + const newView = api.router.sync.router(location) | |
22 | + renderPage(newView) | |
23 | + } | |
24 | +} | |
25 | + | |
26 | +function renderPage (newView) { | |
27 | + const oldView = document.body.firstChild | |
28 | + oldView | |
29 | + ? document.body.replaceChild(newView, oldView) | |
30 | + : document.body.appendChild(newView) | |
31 | +} |
history/sync/push.js | ||
---|---|---|
@@ -1,0 +1,30 @@ | ||
1 | +const nest = require('depnest') | |
2 | + | |
3 | +exports.gives = nest('history.sync.push') | |
4 | + | |
5 | +exports.needs = nest({ | |
6 | + 'history.obs.store': 'first', | |
7 | + 'router.sync.router': 'first' | |
8 | +}) | |
9 | + | |
10 | +exports.create = (api) => { | |
11 | + return nest('history.sync.push', push) | |
12 | + | |
13 | + function push (location) { | |
14 | + const newView = api.router.sync.router(location) | |
15 | + | |
16 | + if (!newView) return | |
17 | + | |
18 | + api.history.obs.store().push(location) | |
19 | + | |
20 | + renderPage(newView) | |
21 | + } | |
22 | +} | |
23 | + | |
24 | +function renderPage (newView) { | |
25 | + const oldView = document.body.firstChild | |
26 | + oldView | |
27 | + ? document.body.replaceChild(newView, oldView) | |
28 | + : document.body.appendChild(newView) | |
29 | + | |
30 | +} |
Built with git-ssb-web