Files: b02d5837685a7fb8e42751b875db010b8ec801c6 / app / html / app.js
1555 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 | startApp() |
34 | |
35 | return app |
36 | } |
37 | }) |
38 | |
39 | function startApp () { |
40 | api.history.sync.push({page: 'splash'}) |
41 | |
42 | setTimeout(enterApp, 2000) |
43 | } |
44 | |
45 | function enterApp() { |
46 | const isOnboarded = api.settings.sync.get('onboarded') |
47 | if (isOnboarded) |
48 | api.history.sync.push({page: 'blogIndex'}) |
49 | else { |
50 | api.history.sync.push({ |
51 | page:'userEdit', |
52 | feed: api.keys.sync.id(), |
53 | callback: (err, didEdit) => { |
54 | if (err) throw new Error ('Error editing profile', err) |
55 | |
56 | // if they clicked something, just mark them onboarded |
57 | api.settings.sync.set({ onboarded: true }) |
58 | |
59 | api.history.sync.push({ page: 'blogIndex' }) |
60 | } |
61 | }) |
62 | } |
63 | |
64 | } |
65 | } |
66 | |
67 |
Built with git-ssb-web