git ssb

2+

mixmix / ticktack



Tree: fee2e3b7fdd8450fbfe1e46220642ed555f52eab

Files: fee2e3b7fdd8450fbfe1e46220642ed555f52eab / router / sync / routes.js

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

Built with git-ssb-web