Files: 3734f09bcf0c150f93dc4e556b99bab42b27be3a / router / sync / routes.js
1926 bytesRaw
1 | const nest = require('depnest') |
2 | const { isMsg, isFeed, isBlob } = 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.channel': 'first', |
9 | 'app.page.settings': 'first', |
10 | 'app.page.groupFind': 'first', |
11 | 'app.page.groupIndex': 'first', |
12 | 'app.page.groupNew': 'first', |
13 | 'app.page.groupShow': 'first', |
14 | 'app.page.userFind': 'first', |
15 | 'app.page.userShow': 'first', |
16 | 'app.page.threadNew': 'first', |
17 | 'app.page.threadShow': 'first', |
18 | 'app.page.image': 'first', |
19 | }) |
20 | |
21 | exports.create = (api) => { |
22 | return nest('router.sync.routes', (sofar = []) => { |
23 | const pages = api.app.page |
24 | // route format: [ routeValidator, routeFunction ] |
25 | |
26 | const routes = [ |
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 | // Thread pages |
34 | // QUESTION - should this be for private threads + group threads? |
35 | [ location => location.page === 'threadNew' && isFeed(location.feed), pages.threadNew ], |
36 | [ location => location.page === 'threadNew' && location.channel, pages.threadNew ], |
37 | [ location => isMsg(location.key), pages.threadShow ], |
38 | |
39 | // User pages |
40 | [ location => location.page === 'userFind', pages.userFind ], |
41 | [ location => isFeed(location.feed), pages.userShow ], |
42 | |
43 | [ location => location.page === 'home', pages.home ], |
44 | [ location => location.page === 'settings', pages.settings ], |
45 | [ location => isBlob(location.blob), pages.image ], |
46 | [ location => location.channel , pages.channel ], |
47 | |
48 | // Error page |
49 | [ location => true, pages.error ] |
50 | ] |
51 | |
52 | return [...routes, ...sofar] |
53 | }) |
54 | } |
55 | |
56 |
Built with git-ssb-web