git ssb

16+

Dominic / patchbay



Tree: 7c78ad02a9f1b3e1bc334486559ed3013e802ec4

Files: 7c78ad02a9f1b3e1bc334486559ed3013e802ec4 / app / html / app.js

1710 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 window: 'reduce',
20 addPage: 'first',
21 catchKeyboardShortcut: 'first'
22 }
23 },
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 const tabs = api.app.html.tabs(initialTabs)
37 const { addPage } = api.app.sync
38
39 const App = h('App', tabs)
40
41 // Catch keyboard shortcuts
42 api.app.sync.catchKeyboardShortcut(window, { tabs })
43
44 // Catch link clicks
45 api.app.async.catchLinkClick(App, (link, { ctrlKey: openBackground, isExternal }) => {
46 if (isExternal) return api.app.html.externalConfirm(link)
47
48 if (tabs.has(link)) tabs.select(link)
49 else {
50 const changeTab = !openBackground
51 addPage(link, changeTab)
52 }
53 })
54
55 // Catch errors
56 var { container: errorPage, content: errorList } = api.app.html.page('/errors')
57 window.addEventListener('error', ev => {
58 if (!tabs.has('/errors')) tabs.add(errorPage, true)
59
60 const error = api.app.html.error(ev.error || ev)
61 errorList.appendChild(error)
62 })
63
64 return App
65 }
66}
67
68function values (object) {
69 const keys = Object.keys(object)
70 return keys.map(k => object[k])
71}
72
73
74

Built with git-ssb-web