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