Files: c26a377b747816479b1dc93f160726ef84bf6205 / app / sync / nav-history.js
1301 bytesRaw
1 | const nest = require('depnest') |
2 | const HyperNav = require('hyper-nav') |
3 | const { h } = require('mutant') |
4 | |
5 | exports.gives = nest({ |
6 | 'app.sync.nav': true, |
7 | 'history.obs.history': true, |
8 | 'history.sync.push': true, |
9 | 'history.sync.back': true, |
10 | }) |
11 | |
12 | exports.needs = nest({ |
13 | 'app.html.header': 'first', |
14 | 'keys.sync.id': 'first', |
15 | 'router.sync.router': 'first', |
16 | 'settings.sync.get': 'first', |
17 | 'settings.sync.set': 'first', |
18 | }) |
19 | |
20 | exports.create = (api) => { |
21 | var nav = null |
22 | |
23 | return nest({ |
24 | 'app.sync.nav': function getNav () { |
25 | if (nav) return nav |
26 | |
27 | nav = HyperNav( |
28 | api.router.sync.router, |
29 | api.app.html.header |
30 | ) |
31 | |
32 | const isOnboarded = api.settings.sync.get('onboarded') |
33 | if (isOnboarded) |
34 | nav.push({page: 'home'}) |
35 | else { |
36 | nav.push({ |
37 | page:'userEdit', |
38 | feed: api.keys.sync.id(), |
39 | callback: (err, didEdit) => { |
40 | if (err) throw new Error ('Error editing profile', err) |
41 | |
42 | if (didEdit) |
43 | api.settings.sync.set({ onboarded: true }) |
44 | |
45 | nav.push({ page: 'home' }) |
46 | } |
47 | }) |
48 | } |
49 | |
50 | return nav |
51 | }, |
52 | 'history.sync.push': (location) => nav.push(location), |
53 | 'history.sync.back': () => nav.back(), |
54 | 'history.obs.history': () => nav.history, |
55 | }) |
56 | } |
57 | |
58 |
Built with git-ssb-web