git ssb

16+

Dominic / patchbay



Tree: c493e24e3dd3c7732099cf62acbabe7501d136f3

Files: c493e24e3dd3c7732099cf62acbabe7501d136f3 / router / sync / routes.js

1962 bytesRaw
1const nest = require('depnest')
2const { isBlobLink, isFeed, isMsg } = require('ssb-ref')
3
4exports.gives = nest('router.sync.routes')
5
6exports.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
28exports.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 => loc.blob && isBlobLink(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
60function isPresent (content) {
61 return typeof content === 'string' && content.length > 1
62}
63

Built with git-ssb-web