Files: d1fa49280765213a3963a4fa7d752ad43d587728 / app / html / app.js
1356 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 | 'router.sync.router': 'first', |
12 | 'settings.sync.get': 'first', |
13 | 'settings.sync.set': 'first', |
14 | }) |
15 | |
16 | exports.create = (api) => { |
17 | return nest({ |
18 | 'app.html.app': function app () { |
19 | api.app.sync.initialize() |
20 | |
21 | var view = Value() |
22 | var app = h('App', view) |
23 | api.history.obs.location()(renderLocation) |
24 | function renderLocation (loc) { |
25 | var page = api.router.sync.router(loc) |
26 | if (page) view.set([ |
27 | api.app.html.header({location: loc, push: api.history.sync.push}), |
28 | page |
29 | ]) |
30 | } |
31 | |
32 | const isOnboarded = api.settings.sync.get('onboarded') |
33 | if (isOnboarded) |
34 | api.history.sync.push({page: 'home'}) |
35 | else { |
36 | api.history.sync.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 | api.history.sync.push({ page: 'home' }) |
46 | } |
47 | }) |
48 | } |
49 | |
50 | |
51 | return app |
52 | } |
53 | }) |
54 | } |
55 | |
56 |
Built with git-ssb-web