git ssb

16+

Dominic / patchbay



Tree: cb96c21f9190d81e56e129d5b7def3e8300c8cbe

Files: cb96c21f9190d81e56e129d5b7def3e8300c8cbe / app / html / app.js

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

Built with git-ssb-web