git ssb

16+

Dominic / patchbay



Tree: dd67652a2a492f8668f29984959b814c9e3cfe6d

Files: dd67652a2a492f8668f29984959b814c9e3cfe6d / router / sync / routes.js

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

Built with git-ssb-web