Files: c6510efde71437dba97e4a87aa9869256d193fb5 / router / sync / routes.js
2535 bytesRaw
1 | const nest = require('depnest') |
2 | const { isMsg, isFeed, isBlob } = require('ssb-ref') |
3 | const openExternal = require('open-external') |
4 | const get = require('lodash/get') |
5 | |
6 | exports.gives = nest('router.sync.routes') |
7 | |
8 | exports.needs = nest({ |
9 | 'app.page.error': 'first', |
10 | 'app.page.blogIndex': 'first', |
11 | 'app.page.blogNew': 'first', |
12 | 'app.page.settings': 'first', |
13 | // 'app.page.channel': 'first', |
14 | // 'app.page.groupFind': 'first', |
15 | // 'app.page.groupIndex': 'first', |
16 | // 'app.page.groupNew': 'first', |
17 | // 'app.page.groupShow': 'first', |
18 | 'app.page.userEdit': 'first', |
19 | // 'app.page.userFind': 'first', |
20 | // 'app.page.userShow': 'first', |
21 | 'app.page.threadNew': 'first', |
22 | 'app.page.threadShow': 'first', |
23 | // 'app.page.image': 'first', |
24 | 'blob.sync.url': 'first', |
25 | }) |
26 | |
27 | exports.create = (api) => { |
28 | return nest('router.sync.routes', (sofar = []) => { |
29 | const pages = api.app.page |
30 | // route format: [ routeValidator, routeFunction ] |
31 | |
32 | const routes = [ |
33 | |
34 | // Thread pages |
35 | // [ location => location.page === 'threadNew' && location.channel, pages.threadNew ], |
36 | [ location => location.page === 'threadNew' && isFeed(location.feed), pages.threadNew ], |
37 | [ location => isMsg(location.key), pages.threadShow ], |
38 | |
39 | // User pages |
40 | // [ location => location.page === 'userFind', pages.userFind ], |
41 | [ location => location.page === 'userEdit' && isFeed(location.feed), pages.userEdit ], |
42 | // [ location => isFeed(location.feed), pages.userShow ], |
43 | |
44 | // Group pages |
45 | // [ location => location.page === 'groupFind', pages.groupFind ], |
46 | // [ location => location.page === 'groupIndex', pages.groupIndex ], |
47 | // [ location => location.page === 'groupNew', pages.groupNew ], |
48 | // // [ location => location.type === 'groupShow' && isMsg(location.key), pages.groupShow ], |
49 | // [ location => location.channel , pages.channel ], |
50 | |
51 | // Blog pages |
52 | [ location => location.page === 'home', pages.blogIndex ], |
53 | [ location => location.page === 'discovery', pages.blogIndex ], |
54 | [ location => location.page === 'blogIndex', pages.blogIndex ], |
55 | [ location => location.page === 'blogNew', pages.blogNew ], |
56 | |
57 | [ location => location.page === 'settings', pages.settings ], |
58 | |
59 | // [ location => isBlob(location.blob), pages.image ], |
60 | [ location => isBlob(location.blob), (location) => { |
61 | openExternal(api.blob.sync.url(location.blob)) |
62 | }], |
63 | |
64 | // Error page |
65 | [ location => true, pages.error ] |
66 | ] |
67 | |
68 | return [...routes, ...sofar] |
69 | }) |
70 | } |
71 | |
72 |
Built with git-ssb-web