Files: b36eaef3214cdcd6186747efbb7421e9d42dba9d / app / sync / goTo.js
1454 bytesRaw
1 | const nest = require('depnest') |
2 | |
3 | exports.gives = nest({ 'app.sync.goTo': true }) |
4 | |
5 | exports.needs = nest({ |
6 | 'app.html.tabs': 'first', |
7 | 'history.obs.store': 'first', |
8 | 'history.sync.push': 'first', |
9 | 'router.sync.normalise': 'first', |
10 | 'router.sync.router': 'first', |
11 | }) |
12 | |
13 | exports.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 | location = api.router.sync.normalise(location) |
26 | const locationId = JSON.stringify(location) |
27 | |
28 | const tabs = api.app.html.tabs() |
29 | if (tabs.has(locationId)) { |
30 | tabs.select(locationId) |
31 | api.history.sync.push(location) |
32 | return true |
33 | } |
34 | |
35 | const page = api.router.sync.router(location) |
36 | if (!page) return |
37 | |
38 | page.id = page.id || locationId |
39 | tabs.add(page, !openBackground, split) |
40 | |
41 | if (openBackground) { |
42 | const history = api.history.obs.store() |
43 | var _history = history() |
44 | var current = _history.pop() |
45 | |
46 | history.set([ ..._history, location, current ]) |
47 | } else { |
48 | api.history.sync.push(location) |
49 | } |
50 | |
51 | return openBackground |
52 | } |
53 | } |
54 |
Built with git-ssb-web