Files: af7e4129360b36c2646ff7a736b53c73d5709ee6 / router / sync / routes.js
1942 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 | 'calendar': 'first', |
9 | 'blob': 'first', |
10 | 'blogs': 'first', |
11 | 'errors': 'first', |
12 | 'channel': 'first', |
13 | 'imageSearch': 'first', |
14 | 'notifications': 'first', |
15 | 'posts': 'first', |
16 | 'postRank': 'first', |
17 | 'private': 'first', |
18 | 'profile': 'first', |
19 | 'public': 'first', |
20 | 'query': 'first', |
21 | 'search': 'first', |
22 | 'settings': 'first', |
23 | 'thread': 'first' |
24 | }, |
25 | 'keys.sync.id': 'first' |
26 | }) |
27 | |
28 | exports.create = (api) => { |
29 | return nest('router.sync.routes', (sofar = []) => { |
30 | const myId = api.keys.sync.id() |
31 | const pages = api.app.page |
32 | |
33 | // loc = location |
34 | const routes = [ |
35 | [ loc => loc.page === 'blogs', pages.blogs ], |
36 | [ loc => loc.page === 'calendar', pages.calendar ], |
37 | [ loc => loc.page === 'errors', pages.errors ], |
38 | [ loc => loc.page === 'imageSearch', pages.imageSearch ], |
39 | [ loc => loc.page === 'notifications', pages.notifications ], |
40 | [ loc => loc.page === 'posts', pages.posts ], |
41 | [ loc => loc.page === 'postRank', pages.postRank ], |
42 | [ loc => loc.page === 'private', pages.private ], |
43 | [ loc => loc.page === 'public', pages.public ], |
44 | [ loc => loc.page === 'profile', () => pages.profile({ feed: myId }) ], |
45 | [ loc => loc.page === 'query', pages.query ], |
46 | [ loc => loc.page === 'search' && loc.query, pages.search ], |
47 | [ loc => loc.page === 'settings', pages.settings ], |
48 | |
49 | [ loc => isBlob(loc.blob), pages.blob ], |
50 | [ loc => isPresent(loc.channel), pages.channel ], |
51 | [ loc => isFeed(loc.feed), pages.profile ], |
52 | [ loc => isMsg(loc.key), pages.thread ] |
53 | ] |
54 | |
55 | // stack already loaded routes on top of these |
56 | return [...sofar, ...routes] |
57 | }) |
58 | } |
59 | |
60 | function isPresent (content) { |
61 | return typeof content === 'string' && content.length > 1 |
62 | } |
63 |
Built with git-ssb-web