git ssb

16+

Dominic / patchbay



Tree: 1a326ad6e229f48d252a5d8e4e8dd65a803f4d58

Files: 1a326ad6e229f48d252a5d8e4e8dd65a803f4d58 / app / sync / goTo.js

1715 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, loc) => {
35 const locationId = api.app.sync.locationId(loc)
36
37 var page = tabs.get(locationId)
38 if (page) {
39 tabs.select(locationId)
40 api.history.sync.push(loc)
41
42 return true
43 }
44
45 api.router.async.router(loc, (err, page) => {
46 if (err) throw err
47
48 if (!page) return
49
50 page.id = page.id || locationId
51 tabs.add(page, !openBackground, split)
52
53 if (openBackground) {
54 const history = api.history.obs.store()
55 var _history = history()
56 var current = _history.pop()
57
58 history.set([ ..._history, loc, current ])
59 } else {
60 api.history.sync.push(loc)
61 }
62 })
63 })
64 }
65}
66

Built with git-ssb-web