git ssb

16+

Dominic / patchbay



Tree: 8069cbb074f6985dedd767cc31ba0586638550ea

Files: 8069cbb074f6985dedd767cc31ba0586638550ea / app / sync / goTo.js

1999 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 var page = tabs.get(locationId)
38 if (page) {
39 tabs.select(locationId)
40
41 if (location.value) { // if there's a value it's not just a hydrated locationId
42 if (page && page.firstChild && page.firstChild.scrollDownToMessage) {
43 page.firstChild.scrollDownToMessage(location.key)
44 }
45 }
46
47 api.history.sync.push(location)
48
49 return true
50 }
51
52 api.router.async.router(location, (err, page) => {
53 if (err) throw err
54
55 if (!page) return
56
57 page.id = page.id || locationId
58 tabs.add(page, !openBackground, split)
59
60 if (openBackground) {
61 const history = api.history.obs.store()
62 var _history = history()
63 var current = _history.pop()
64
65 history.set([ ..._history, location, current ])
66 } else {
67 api.history.sync.push(location)
68 }
69 })
70 })
71 }
72}
73

Built with git-ssb-web