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