Files: a8f5b5e7e64eb476a62fe7e8a36a494c83a661d8 / router / sync / routes.js
1462 bytesRaw
1 | const nest = require('depnest') |
2 | const { isBlob, isFeed, isMsg } = require('ssb-ref') |
3 | |
4 | exports.gives = nest('router.sync.routes') |
5 | |
6 | exports.needs = nest({ |
7 | 'app.page': { |
8 | 'errors': 'first', |
9 | 'public': 'first', |
10 | 'private': 'first', |
11 | 'notifications': 'first', |
12 | 'profile': 'first', |
13 | 'search': 'first', |
14 | 'blob': 'first', |
15 | 'thread': 'first', |
16 | 'channel': 'first', |
17 | 'settings': 'first' |
18 | |
19 | }, |
20 | 'keys.sync.id': 'first' |
21 | }) |
22 | |
23 | exports.create = (api) => { |
24 | return nest('router.sync.routes', (sofar = []) => { |
25 | const myId = api.keys.sync.id() |
26 | const pages = api.app.page |
27 | |
28 | // loc = location |
29 | const routes = [ |
30 | [ loc => loc.page === 'public', pages.public ], |
31 | [ loc => loc.page === 'private', pages.private ], |
32 | [ loc => loc.page === 'notifications', pages.notifications ], |
33 | [ loc => loc.page === 'errors', pages.errors ], |
34 | [ loc => loc.page === 'profile', () => pages.profile({ feed: myId }) ], |
35 | [ loc => loc.page === 'search' && loc.query, pages.search ], |
36 | [ loc => loc.page === 'settings', pages.settings], |
37 | |
38 | [ loc => isBlob(loc.blob), pages.blob ], |
39 | [ loc => isPresent(loc.channel), pages.channel ], |
40 | [ loc => isFeed(loc.feed), pages.profile ], |
41 | [ loc => isMsg(loc.key), pages.thread ] |
42 | ] |
43 | |
44 | // stack already loaded routes on top of these |
45 | return [...sofar, ...routes] |
46 | }) |
47 | } |
48 | |
49 | function isPresent (content) { |
50 | return typeof content === 'string' && content.length > 1 |
51 | } |
52 |
Built with git-ssb-web