Files: 0e65bf76f75d4874321e893134b730597473287e / app / html / app.js
1939 bytesRaw
1 | const nest = require('depnest') |
2 | const values = require('lodash/values') |
3 | const insertCss = require('insert-css') |
4 | const openExternal = require('open-external') |
5 | |
6 | const HyperNav = require('hyper-nav') |
7 | const computed = require('mutant/computed') |
8 | const h = require('mutant/h') |
9 | |
10 | exports.gives = nest({ |
11 | 'app.html.app': true, |
12 | 'history.obs.history': true, |
13 | 'history.sync.push': true, |
14 | 'history.sync.back': true, |
15 | }) |
16 | |
17 | exports.needs = nest({ |
18 | 'about.async.suggest': 'first', |
19 | 'app.html.header': 'first', |
20 | 'app.async.catchLinkClick': 'first', |
21 | 'channel.async.suggest': 'first', |
22 | 'keys.sync.id': 'first', |
23 | 'router.sync.router': 'first', |
24 | 'settings.sync.get': 'first', |
25 | 'settings.sync.set': 'first', |
26 | 'styles.css': 'reduce', |
27 | }) |
28 | |
29 | exports.create = (api) => { |
30 | var nav = null |
31 | |
32 | return nest({ |
33 | 'app.html.app': function app () { |
34 | |
35 | // DIRTY HACK - initializes the suggestion indexes |
36 | api.about.async.suggest() |
37 | api.channel.async.suggest() |
38 | |
39 | const css = values(api.styles.css()).join('\n') |
40 | insertCss(css) |
41 | |
42 | api.app.async.catchLinkClick(document.body, (link, { isExternal }) => { |
43 | if (isExternal) return openExternal(link) |
44 | nav.push(link) |
45 | }) |
46 | |
47 | nav = HyperNav( |
48 | api.router.sync.router, |
49 | api.app.html.header |
50 | ) |
51 | |
52 | const isOnboarded = api.settings.sync.get('onboarded') |
53 | if (isOnboarded) |
54 | nav.push({page: 'home'}) |
55 | else { |
56 | nav.push({ |
57 | page:'userEdit', |
58 | feed: api.keys.sync.id(), |
59 | callback: (err, didEdit) => { |
60 | if (err) throw new Error ('Error editing profile', err) |
61 | |
62 | if (didEdit) |
63 | api.settings.sync.set({ onboarded: true }) |
64 | |
65 | nav.push({ page: 'home' }) |
66 | } |
67 | }) |
68 | } |
69 | |
70 | return nav |
71 | }, |
72 | 'history.sync.push': (location) => nav.push(location), |
73 | 'history.sync.back': () => nav.back(), |
74 | 'history.obs.history': () => nav.history, |
75 | }) |
76 | } |
77 | |
78 | |
79 | |
80 |
Built with git-ssb-web