git ssb

16+

Dominic / patchbay



Tree: 5e5bef4d7a2202ff89f9fd54978ed73376abe898

Files: 5e5bef4d7a2202ff89f9fd54978ed73376abe898 / app / html / app.js

1986 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.async.catchLinkClick': 'first',
9 'app.html.error': 'first',
10 'app.html.externalConfirm': 'first',
11 'app.html.tabs': 'first',
12 'app.sync.window': 'reduce',
13 'app.sync.addPage': 'first',
14 'app.sync.catchKeyboardShortcut': 'first',
15 'router.sync.router': 'first',
16 'router.sync.normalise': 'first',
17 'styles.css': 'reduce'
18})
19
20exports.create = function (api) {
21 return nest('app.html.app', app)
22
23 function app () {
24 window = api.app.sync.window(window)
25 const css = values(api.styles.css()).join('\n')
26 insertCss(css)
27
28 const initialTabs = [ '/public', '/private', '/notifications' ]
29 // NB router converts these to { page: '/public' }
30 const tabs = api.app.html.tabs(initialTabs)
31
32 const App = h('App', tabs)
33
34 // Catch keyboard shortcuts
35 api.app.sync.catchKeyboardShortcut(window, { tabs })
36
37 // Catch link clicks
38 api.app.async.catchLinkClick(App, (link, { ctrlKey: openBackground, isExternal }) => {
39 if (isExternal) return api.app.html.externalConfirm(link)
40
41 // TODO tidy up who and where this logic happens (do when adding patch-history)
42 const location = api.router.sync.normalise(link)
43 const tabId = JSON.stringify(location)
44 if (tabs.has(tabId)) tabs.select(tabId)
45 else {
46 const changeTab = !openBackground
47 api.app.sync.addPage(location, changeTab)
48 }
49 })
50
51 // Catch errors
52 // var { container: errorPage, content: errorList } = api.router.sync.router('/errors')
53 // window.addEventListener('error', ev => {
54 // if (!tabs.has('/errors')) tabs.add(errorPage, true)
55
56 // const error = api.app.html.error(ev.error || ev)
57 // errorList.appendChild(error)
58 // })
59
60 return App
61 }
62}
63
64function values (object) {
65 const keys = Object.keys(object)
66 return keys.map(k => object[k])
67}
68

Built with git-ssb-web