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