git ssb

16+

Dominic / patchbay



Tree: dc2e96d4d0a86072d9393a2d15d786a80cb341ff

Files: dc2e96d4d0a86072d9393a2d15d786a80cb341ff / app / sync / goTo.js

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

Built with git-ssb-web