Commit d2ef619dd77cafe0c113840831438790127a1875
Merge pull request #9 from ticktackim/all_pages
add placeholders for all pages, add new app.html.link helpermix irving authored on 8/14/2017, 5:36:29 AM
GitHub committed on 8/14/2017, 5:36:29 AM
Parent: 49bee78f3c1fec7174a11ee2c7277f5c9a7f47fc
Parent: aa385bc7adcc17f7091af60e79e1cd9802cc5dfe
Files changed
app/html/app.js | changed |
app/html/nav.js | changed |
app/html/nav.mcss | changed |
app/html/link.js | added |
app/index.js | changed |
app/page/home.js | changed |
app/page/group.js | deleted |
app/page/error.js | added |
app/page/groupFind.js | added |
app/page/groupIndex.js | added |
app/page/groupNew.js | added |
app/page/private.js | deleted |
app/page/groupShow.js | added |
app/page/settings.js | added |
app/page/threadShow.js | added |
app/page/userFind.js | added |
app/page/userShow.js | added |
router/sync/routes.js | changed |
app/html/app.js | ||
---|---|---|
@@ -27,9 +27,9 @@ | ||
27 | 27 | api.history.sync.push(link) |
28 | 28 | }) |
29 | 29 | |
30 | 30 | api.history.obs.location()(render) |
31 | - api.history.sync.push({ page: 'home' }) | |
31 | + api.history.sync.push({ page: 'settings' }) | |
32 | 32 | } |
33 | 33 | |
34 | 34 | function render (location) { |
35 | 35 | const newView = api.router.sync.router(location) |
app/html/nav.js | ||
---|---|---|
@@ -3,8 +3,9 @@ | ||
3 | 3 | |
4 | 4 | exports.gives = nest('app.html.nav') |
5 | 5 | |
6 | 6 | exports.needs = nest({ |
7 | + 'app.html.link': 'first', | |
7 | 8 | 'history.sync.push': 'first', |
8 | 9 | 'history.sync.back': 'first' |
9 | 10 | }) |
10 | 11 | |
@@ -12,14 +13,18 @@ | ||
12 | 13 | return nest('app.html.nav', nav) |
13 | 14 | |
14 | 15 | function nav (id) { |
15 | 16 | const { push, back } = api.history.sync |
17 | + | |
18 | + const goHome = () => push({page: 'home'}) | |
19 | + // CHANGE THIS : zero history | |
20 | + const Link = api.app.html.link | |
21 | + | |
16 | 22 | return h('Nav', [ |
17 | 23 | h('div.back', { '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'}) }, 'Thread A'), | |
21 | - h('div', { 'ev-click': () => push({key: '%3cWZHeN6k03XpvDBxrxP5bGLsNByFLTvr/rKYFV4f+c=.sha256'}) }, 'Thread B'), | |
22 | - h('a', { href: '%YRhFXmsAwipgyiwuHSP+EBr9fGjSqrMpWXUxgWcHxkM=.sha256' }, 'href link') | |
24 | + h('div', { 'ev-click': goHome }, 'Home'), | |
25 | + Link({ page: 'settings' }, 'Settings'), | |
26 | + Link({ page: 'userFind' }, 'Find a User'), | |
27 | + h('a', { href: '%YRhFXmsAwipgyiwuHSP+EBr9fGjSqrMpWXUxgWcHxkM=.sha256' }, 'A Thread') | |
23 | 28 | ]) |
24 | 29 | } |
25 | 30 | } |
app/html/nav.mcss | ||
---|---|---|
@@ -3,9 +3,10 @@ | ||
3 | 3 | align-items: center |
4 | 4 | |
5 | 5 | margin: 0 0 1rem 1rem |
6 | 6 | |
7 | - div { | |
7 | + a, div { | |
8 | + color: #222 | |
8 | 9 | margin-right: 1rem |
9 | 10 | |
10 | 11 | :hover { |
11 | 12 | text-decoration: underline |
app/html/link.js | ||
---|---|---|
@@ -1,0 +1,17 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { h } = require('mutant') | |
3 | + | |
4 | +exports.gives = nest('app.html.link') | |
5 | + | |
6 | +exports.needs = nest({ | |
7 | + 'history.sync.push': 'first', | |
8 | +}) | |
9 | + | |
10 | +exports.create = (api) => { | |
11 | + return nest('app.html.link', (location, body) => { | |
12 | + return h('Link', { | |
13 | + 'ev-click': () => api.history.sync.push(location) | |
14 | + }, body) | |
15 | + }) | |
16 | +} | |
17 | + |
app/index.js | ||
---|---|---|
@@ -4,12 +4,20 @@ | ||
4 | 4 | }, |
5 | 5 | html: { |
6 | 6 | app: require('./html/app'), |
7 | 7 | thread: require('./html/thread'), |
8 | - nav: require('./html/nav') | |
8 | + link: require('./html/link'), | |
9 | + nav: require('./html/nav'), | |
9 | 10 | }, |
10 | 11 | page: { |
11 | - group: require('./page/group'), | |
12 | + error: require('./page/error'), | |
13 | + groupFind: require('./page/groupFind'), | |
14 | + groupIndex: require('./page/groupIndex'), | |
15 | + groupNew: require('./page/groupNew'), | |
16 | + groupShow: require('./page/groupShow'), | |
12 | 17 | home: require('./page/home'), |
13 | - private: require('./page/private') | |
18 | + settings: require('./page/settings'), | |
19 | + userFind: require('./page/userFind'), | |
20 | + userShow: require('./page/userShow'), | |
21 | + threadShow: require('./page/threadShow'), | |
14 | 22 | } |
15 | 23 | } |
app/page/home.js | ||
---|---|---|
@@ -59,8 +59,9 @@ | ||
59 | 59 | var container = h('div.container', []) |
60 | 60 | |
61 | 61 | function subject (msg) { |
62 | 62 | const { subject, text } = msg.value.content |
63 | + | |
63 | 64 | return api.message.html.markdown(firstLine(subject|| text)) |
64 | 65 | } |
65 | 66 | |
66 | 67 | function link(location) { |
app/page/group.js | ||
---|---|---|
@@ -1,23 +1,0 @@ | ||
1 | -const nest = require('depnest') | |
2 | -const { h } = require('mutant') | |
3 | - | |
4 | -exports.gives = nest('app.page.group') | |
5 | - | |
6 | -exports.needs = nest({ | |
7 | - 'app.html.nav': 'first' | |
8 | -}) | |
9 | - | |
10 | -exports.create = (api) => { | |
11 | - return nest('app.page.group', group) | |
12 | - | |
13 | - function group (location) { | |
14 | - // location here can be the root message of a group : { type: 'group', key } | |
15 | - // TODO show specific group index described by key | |
16 | - | |
17 | - return h('Page -group', [ | |
18 | - h('h1', 'Group'), | |
19 | - api.app.html.nav(), | |
20 | - h('p', `key: ${location.key}`) | |
21 | - ]) | |
22 | - } | |
23 | -} |
app/page/error.js | ||
---|---|---|
@@ -1,0 +1,22 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { h } = require('mutant') | |
3 | + | |
4 | +exports.gives = nest('app.page.error') | |
5 | + | |
6 | +exports.needs = nest({ | |
7 | + 'app.html.nav': 'first' | |
8 | +}) | |
9 | + | |
10 | +exports.create = (api) => { | |
11 | + return nest('app.page.error', error) | |
12 | + | |
13 | + function error (location) { | |
14 | + | |
15 | + return h('Page -error', [ | |
16 | + h('h1', 'Error'), | |
17 | + api.app.html.nav(), | |
18 | + "The route wasn't found of there was an error", | |
19 | + location.error | |
20 | + ]) | |
21 | + } | |
22 | +} |
app/page/groupFind.js | ||
---|---|---|
@@ -1,0 +1,21 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { h } = require('mutant') | |
3 | + | |
4 | +exports.gives = nest('app.page.groupFind') | |
5 | + | |
6 | +exports.needs = nest({ | |
7 | + 'app.html.nav': 'first' | |
8 | +}) | |
9 | + | |
10 | +exports.create = (api) => { | |
11 | + return nest('app.page.groupFind', groupFind) | |
12 | + | |
13 | + function groupFind (location) { | |
14 | + | |
15 | + return h('Page -groupFind', [ | |
16 | + h('h1', 'Group Find'), | |
17 | + api.app.html.nav(), | |
18 | + h('p', `key: ${location.key}`) | |
19 | + ]) | |
20 | + } | |
21 | +} |
app/page/groupIndex.js | ||
---|---|---|
@@ -1,0 +1,19 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { h } = require('mutant') | |
3 | + | |
4 | +exports.gives = nest('app.page.groupIndex') | |
5 | + | |
6 | +exports.needs = nest({ | |
7 | + 'app.html.nav': 'first' | |
8 | +}) | |
9 | + | |
10 | +exports.create = (api) => { | |
11 | + return nest('app.page.groupIndex', groupIndex) | |
12 | + | |
13 | + function groupIndex (location) { | |
14 | + return h('Page -groupIndex', [ | |
15 | + h('h1', 'Group Index'), | |
16 | + api.app.html.nav() | |
17 | + ]) | |
18 | + } | |
19 | +} |
app/page/groupNew.js | ||
---|---|---|
@@ -1,0 +1,19 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { h } = require('mutant') | |
3 | + | |
4 | +exports.gives = nest('app.page.groupNew') | |
5 | + | |
6 | +exports.needs = nest({ | |
7 | + 'app.html.nav': 'first' | |
8 | +}) | |
9 | + | |
10 | +exports.create = (api) => { | |
11 | + return nest('app.page.groupNew', groupNew) | |
12 | + | |
13 | + function groupNew (location) { | |
14 | + return h('Page -groupNew', [ | |
15 | + h('h1', 'Group New'), | |
16 | + api.app.html.nav() | |
17 | + ]) | |
18 | + } | |
19 | +} |
app/page/private.js | ||
---|---|---|
@@ -1,25 +1,0 @@ | ||
1 | -const nest = require('depnest') | |
2 | -const { h } = require('mutant') | |
3 | - | |
4 | -exports.gives = nest('app.page.private') | |
5 | - | |
6 | -exports.needs = nest({ | |
7 | - 'app.html.nav': 'first', | |
8 | - 'app.html.thread': 'first' | |
9 | -}) | |
10 | - | |
11 | -exports.create = (api) => { | |
12 | - return nest('app.page.private', privatePage) | |
13 | - | |
14 | - function privatePage (location) { | |
15 | - // location here can expected to be an ssb-message | |
16 | - | |
17 | - const thread = api.app.html.thread(location.key) | |
18 | - | |
19 | - return h('Page -private', [ | |
20 | - h('h1', 'Private message'), | |
21 | - api.app.html.nav(), | |
22 | - h('div.container', thread) | |
23 | - ]) | |
24 | - } | |
25 | -} |
app/page/groupShow.js | ||
---|---|---|
@@ -1,0 +1,23 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { h } = require('mutant') | |
3 | + | |
4 | +exports.gives = nest('app.page.groupShow') | |
5 | + | |
6 | +exports.needs = nest({ | |
7 | + 'app.html.nav': 'first' | |
8 | +}) | |
9 | + | |
10 | +exports.create = (api) => { | |
11 | + return nest('app.page.groupShow', groupShow) | |
12 | + | |
13 | + function groupShow (location) { | |
14 | + // location here can be the root message of a group : { type: 'group', key } | |
15 | + // TODO show specific group index described by key | |
16 | + | |
17 | + return h('Page -groupShow', [ | |
18 | + h('h1', 'Group Show'), | |
19 | + api.app.html.nav(), | |
20 | + h('p', `key: ${location.key}`) | |
21 | + ]) | |
22 | + } | |
23 | +} |
app/page/settings.js | ||
---|---|---|
@@ -1,0 +1,20 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { h } = require('mutant') | |
3 | + | |
4 | +exports.gives = nest('app.page.settings') | |
5 | + | |
6 | +exports.needs = nest({ | |
7 | + 'app.html.nav': 'first' | |
8 | +}) | |
9 | + | |
10 | +exports.create = (api) => { | |
11 | + return nest('app.page.settings', settings) | |
12 | + | |
13 | + function settings (location) { | |
14 | + | |
15 | + return h('Page -settings', [ | |
16 | + h('h1', 'Settings'), | |
17 | + api.app.html.nav(), | |
18 | + ]) | |
19 | + } | |
20 | +} |
app/page/threadShow.js | ||
---|---|---|
@@ -1,0 +1,25 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { h } = require('mutant') | |
3 | + | |
4 | +exports.gives = nest('app.page.threadShow') | |
5 | + | |
6 | +exports.needs = nest({ | |
7 | + 'app.html.nav': 'first', | |
8 | + 'app.html.thread': 'first' | |
9 | +}) | |
10 | + | |
11 | +exports.create = (api) => { | |
12 | + return nest('app.page.threadShow', threadShow) | |
13 | + | |
14 | + function threadShow (location) { | |
15 | + // location here can expected to be an ssb-message | |
16 | + | |
17 | + const thread = api.app.html.thread(location.key) | |
18 | + | |
19 | + return h('Page -threadShow', [ | |
20 | + h('h1', 'Private message'), | |
21 | + api.app.html.nav(), | |
22 | + h('div.container', thread) | |
23 | + ]) | |
24 | + } | |
25 | +} |
app/page/userFind.js | ||
---|---|---|
@@ -1,0 +1,20 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { h } = require('mutant') | |
3 | + | |
4 | +exports.gives = nest('app.page.userFind') | |
5 | + | |
6 | +exports.needs = nest({ | |
7 | + 'app.html.nav': 'first' | |
8 | +}) | |
9 | + | |
10 | +exports.create = (api) => { | |
11 | + return nest('app.page.userFind', userFind) | |
12 | + | |
13 | + function userFind (location) { | |
14 | + | |
15 | + return h('Page -userFind', [ | |
16 | + h('h1', 'Find a User'), | |
17 | + api.app.html.nav() | |
18 | + ]) | |
19 | + } | |
20 | +} |
app/page/userShow.js | ||
---|---|---|
@@ -1,0 +1,21 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { h } = require('mutant') | |
3 | + | |
4 | +exports.gives = nest('app.page.userShow') | |
5 | + | |
6 | +exports.needs = nest({ | |
7 | + 'app.html.nav': 'first' | |
8 | +}) | |
9 | + | |
10 | +exports.create = (api) => { | |
11 | + return nest('app.page.userShow', userShow) | |
12 | + | |
13 | + function userShow (location) { | |
14 | + | |
15 | + return h('Page -userShow', [ | |
16 | + h('h1', 'User show'), | |
17 | + api.app.html.nav(), | |
18 | + h('p', `key: ${location.key}`) | |
19 | + ]) | |
20 | + } | |
21 | +} |
router/sync/routes.js | ||
---|---|---|
@@ -1,12 +1,19 @@ | ||
1 | 1 | const nest = require('depnest') |
2 | -const ref = require('ssb-ref') | |
2 | +const { isMsg, isFeed } = require('ssb-ref') | |
3 | 3 | exports.gives = nest('router.sync.routes') |
4 | 4 | |
5 | 5 | exports.needs = nest({ |
6 | + 'app.page.error': 'first', | |
6 | 7 | 'app.page.home': 'first', |
7 | - 'app.page.group': 'first', | |
8 | - 'app.page.private': 'first' | |
8 | + 'app.page.settings': 'first', | |
9 | + 'app.page.groupFind': 'first', | |
10 | + 'app.page.groupIndex': 'first', | |
11 | + 'app.page.groupNew': 'first', | |
12 | + 'app.page.groupShow': 'first', | |
13 | + 'app.page.userFind': 'first', | |
14 | + 'app.page.userShow': 'first', | |
15 | + 'app.page.threadShow': 'first' | |
9 | 16 | }) |
10 | 17 | |
11 | 18 | exports.create = (api) => { |
12 | 19 | return nest('router.sync.routes', (sofar = []) => { |
@@ -14,11 +21,26 @@ | ||
14 | 21 | // route format: [ routeValidator, routeFunction ] |
15 | 22 | |
16 | 23 | const routes = [ |
17 | 24 | [ location => location.page === 'home', pages.home ], |
18 | - [ location => location.type === 'group', pages.group ], | |
19 | - [ location => location.page === 'channel', pages.channel ], | |
20 | - [ location => ref.isMsg(location.key), pages.private ] | |
25 | + [ location => location.page === 'settings', pages.settings ], | |
26 | + | |
27 | + // Group pages | |
28 | + [ location => location.page === 'groupFind', pages.groupFind ], | |
29 | + [ location => location.page === 'groupIndex', pages.groupIndex ], | |
30 | + [ location => location.page === 'groupNew', pages.groupNew ], | |
31 | + [ location => location.type === 'groupShow' && isMsg(location.key), pages.groupShow ], | |
32 | + | |
33 | + // User pages | |
34 | + [ location => location.page === 'userFind', pages.userFind ], | |
35 | + [ location => isFeed(location.feed), pages.userShow ], | |
36 | + | |
37 | + // Thread pages | |
38 | + // QUESTION - should this be for private threads + group threads? | |
39 | + [ location => isMsg(location.key), pages.threadShow ], | |
40 | + | |
41 | + // Error page | |
42 | + [ location => true, pages.error ] | |
21 | 43 | ] |
22 | 44 | |
23 | 45 | return [...routes, ...sofar] |
24 | 46 | }) |
Built with git-ssb-web