git ssb

16+

Dominic / patchbay



Tree: 109a8e516aa40324eb7ee406afb7d35b0d0be031

Files: 109a8e516aa40324eb7ee406afb7d35b0d0be031 / app / html / app.js

1644 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 page: 'first'
17 },
18 sync: {
19 addPage: 'first',
20 catchKeyboardShortcut: 'first'
21 }
22 },
23 'styles.css': 'reduce'
24})
25
26exports.create = function (api) {
27 return nest('app.html.app', app)
28
29 function app () {
30 const css = values(api.styles.css()).join('\n')
31 insertCss(css)
32
33 const initialTabs = ['/public', '/private', '/notifications']
34 const tabs = api.app.html.tabs(initialTabs)
35 const { addPage } = api.app.sync
36
37 const App = h('App', tabs)
38
39 // Catch keyboard shortcuts
40 api.app.sync.catchKeyboardShortcut(window, { tabs })
41
42 // Catch link clicks
43 api.app.async.catchLinkClick(App, (link, { ctrlKey: openBackground, isExternal }) => {
44 if (isExternal) return api.app.html.externalConfirm(link)
45
46 if (tabs.has(link)) tabs.select(link)
47 else {
48 const changeTab = !openBackground
49 addPage(link, changeTab)
50 }
51 })
52
53 // Catch errors
54 var { container: errorPage, content: errorList } = api.app.html.page('/errors')
55 window.addEventListener('error', ev => {
56 if (!tabs.has('/errors')) tabs.add(errorPage, true)
57
58 const error = api.app.html.error(ev.error || ev)
59 errorList.appendChild(error)
60 })
61
62 return App
63 }
64}
65
66function values (object) {
67 const keys = Object.keys(object)
68 return keys.map(k => object[k])
69}
70
71

Built with git-ssb-web