git ssb

16+

Dominic / patchbay



Tree: d5d67784390b67e685e8675d95cabae952961b35

Files: d5d67784390b67e685e8675d95cabae952961b35 / app / sync / goTo.js

1651 bytesRaw
1const nest = require('depnest')
2
3exports.gives = nest({ 'app.sync.goTo': true })
4
5exports.needs = nest({
6 'app.html.tabs': 'first',
7 'history.obs.store': 'first',
8 'history.sync.push': 'first',
9 'router.async.normalise': 'first',
10 'router.async.router': 'first'
11})
12
13exports.create = function (api) {
14 return nest('app.sync.goTo', goTo)
15
16 // TODO consider rolling single arg:
17 // goTo({ ...location, tmp: { openBackground, split, position } })
18 //
19 // prune `tmp` before pushing into history
20 // allows a refactor of catch-keyboard-shortcut + patch-inbox
21 // - extracts scrollToMessage into app.page.thread
22 // - router.sync.router would take (location, { position }) ?
23
24 function goTo (location, openBackground = false, split = false) {
25 api.router.async.normalise(location, (err, location) => {
26 if (err) throw err
27
28 const locationId = JSON.stringify(location)
29
30 const tabs = api.app.html.tabs()
31 if (tabs.has(locationId)) {
32 tabs.select(locationId)
33 api.history.sync.push(location)
34 return true
35 }
36
37 api.router.async.router(location, (err, page) => {
38 debugger
39 if (err) throw err
40
41 if (!page) return
42
43 page.id = page.id || locationId
44 tabs.add(page, !openBackground, split)
45
46 if (openBackground) {
47 const history = api.history.obs.store()
48 var _history = history()
49 var current = _history.pop()
50
51 history.set([ ..._history, location, current ])
52 } else {
53 api.history.sync.push(location)
54 }
55 })
56
57 // return openBackground // might not be needed?
58 })
59 }
60}
61

Built with git-ssb-web