git ssb

16+

Dominic / patchbay



Tree: feaef7416161fe384b1f54730d4ed4ef362082ba

Files: feaef7416161fe384b1f54730d4ed4ef362082ba / app / sync / goTo.js

2031 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 if (err) return console.error(err)
36
37 const locationId = api.app.sync.locationId(loc)
38
39 var page = tabs.get(locationId)
40
41 if (page) {
42 tabs.select(locationId)
43 api.history.sync.push(loc)
44
45 if (loc.action === 'quote' && page.firstChild && page.firstChild.addQuote) {
46 page.firstChild.addQuote(loc.value)
47 tabs.currentPage().keyboardScroll('last')
48 } else if (loc.action === 'reply') { tabs.currentPage().keyboardScroll('last') }
49
50 return true
51 }
52
53 api.router.async.router(loc, (err, page) => {
54 if (err) throw err
55
56 if (!page) return
57
58 page.id = page.id || locationId
59 tabs.add(page, !openBackground, split)
60
61 if (openBackground) {
62 const history = api.history.obs.store()
63 var _history = history()
64 var current = _history.pop()
65
66 history.set([ ..._history, loc, current ])
67 } else {
68 api.history.sync.push(loc)
69 }
70 })
71 })
72 }
73}
74

Built with git-ssb-web