Files: d2ef619dd77cafe0c113840831438790127a1875 / router / sync / routes.js
1534 bytesRaw
1 | const nest = require('depnest') |
2 | const { isMsg, isFeed } = require('ssb-ref') |
3 | exports.gives = nest('router.sync.routes') |
4 | |
5 | exports.needs = nest({ |
6 | 'app.page.error': 'first', |
7 | 'app.page.home': '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' |
16 | }) |
17 | |
18 | exports.create = (api) => { |
19 | return nest('router.sync.routes', (sofar = []) => { |
20 | const pages = api.app.page |
21 | // route format: [ routeValidator, routeFunction ] |
22 | |
23 | const routes = [ |
24 | [ location => location.page === 'home', pages.home ], |
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 ] |
43 | ] |
44 | |
45 | return [...routes, ...sofar] |
46 | }) |
47 | } |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 |
Built with git-ssb-web