git ssb

16+

Dominic / patchbay



Tree: 9510d7867738dfa7a4aaee17c183c86bb081f55e

Files: 9510d7867738dfa7a4aaee17c183c86bb081f55e / app / html / app.js

1804 bytesRaw
1const nest = require('depnest')
2const { h } = require('mutant')
3const insertCss = require('insert-css')
4
5exports.gives = nest('app.html.app')
6
7exports.needs = nest({
8 app: {
9 async: {
10 catchLinkClick: 'first'
11 },
12 html: {
13 error: 'first',
14 externalConfirm: 'first',
15 tabs: 'first',
16 },
17 sync: {
18 window: 'reduce',
19 addPage: 'first',
20 catchKeyboardShortcut: 'first',
21 }
22 },
23 'router.sync.router': 'first',
24 'styles.css': 'reduce'
25})
26
27exports.create = function (api) {
28 return nest('app.html.app', app)
29
30 function app () {
31 window = api.app.sync.window(window)
32 const css = values(api.styles.css()).join('\n')
33 insertCss(css)
34
35 const initialTabs = [ '/public', '/private', '/notifications' ]
36 // NB router converts these to { page: '/public' }
37 const tabs = api.app.html.tabs(initialTabs)
38 const { addPage } = api.app.sync
39
40 const App = h('App', tabs)
41
42 // Catch keyboard shortcuts
43 api.app.sync.catchKeyboardShortcut(window, { tabs })
44
45 // Catch link clicks
46 api.app.async.catchLinkClick(App, (link, { ctrlKey: openBackground, isExternal }) => {
47 if (isExternal) return api.app.html.externalConfirm(link)
48
49 if (tabs.has(link)) tabs.select(link)
50 else {
51 const changeTab = !openBackground
52 addPage(link, changeTab)
53 }
54 })
55
56 // Catch errors
57 // var { container: errorPage, content: errorList } = api.router.sync.router('/errors')
58 // window.addEventListener('error', ev => {
59 // if (!tabs.has('/errors')) tabs.add(errorPage, true)
60
61 // const error = api.app.html.error(ev.error || ev)
62 // errorList.appendChild(error)
63 // })
64
65 return App
66 }
67}
68
69function values (object) {
70 const keys = Object.keys(object)
71 return keys.map(k => object[k])
72}
73
74
75

Built with git-ssb-web