git ssb

2+

mixmix / ticktack



Tree: cf39375daad7bbcd8a42807ea1459802a41ee050

Files: cf39375daad7bbcd8a42807ea1459802a41ee050 / router / sync / routes.js

1982 bytesRaw
1const nest = require('depnest')
2const { isMsg, isFeed, isBlob } = require('ssb-ref')
3exports.gives = nest('router.sync.routes')
4
5exports.needs = nest({
6 'app.page.error': 'first',
7 'app.page.home': 'first',
8 'app.page.channel': 'first',
9 'app.page.settings': 'first',
10 'app.page.groupFind': 'first',
11 'app.page.groupIndex': 'first',
12 'app.page.groupNew': 'first',
13 'app.page.groupShow': 'first',
14 'app.page.userEdit': 'first',
15 'app.page.userFind': 'first',
16 'app.page.userShow': 'first',
17 'app.page.threadNew': 'first',
18 'app.page.threadShow': 'first',
19 'app.page.image': 'first',
20})
21
22exports.create = (api) => {
23 return nest('router.sync.routes', (sofar = []) => {
24 const pages = api.app.page
25 // route format: [ routeValidator, routeFunction ]
26
27 const routes = [
28
29 // Thread pages
30 [ location => location.page === 'threadNew' && isFeed(location.feed), pages.threadNew ],
31 [ location => location.page === 'threadNew' && location.channel, pages.threadNew ],
32 [ location => isMsg(location.key), pages.threadShow ],
33
34 // User pages
35 [ location => location.page === 'userFind', pages.userFind ],
36 [ location => location.page === 'userEdit' && isFeed(location.feed), pages.userEdit ],
37 [ location => isFeed(location.feed), pages.userShow ],
38
39 // Group pages
40 [ location => location.page === 'groupFind', pages.groupFind ],
41 [ location => location.page === 'groupIndex', pages.groupIndex ],
42 [ location => location.page === 'groupNew', pages.groupNew ],
43 // [ location => location.type === 'groupShow' && isMsg(location.key), pages.groupShow ],
44 [ location => location.channel , pages.channel ],
45
46 [ location => location.page === 'home', pages.home ],
47 [ location => location.page === 'settings', pages.settings ],
48 [ location => isBlob(location.blob), pages.image ],
49
50 // Error page
51 [ location => true, pages.error ]
52 ]
53
54 return [...routes, ...sofar]
55 })
56}
57
58

Built with git-ssb-web