-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.js
42 lines (33 loc) · 1020 Bytes
/
route.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { h } from './lib/h.js'
import { composer } from './composer.js'
import { bogbot } from './bogbot.js'
import { adder } from './adder.js'
import { gossip } from './gossip.js'
import { settings } from './settings.js'
export const route = async (container) => {
const screen = h('div', {id: 'screen'})
const scroller = h('div', {id: 'scroller'})
const controls = h('div', {id: 'controls'})
scroller.appendChild(controls)
container.appendChild(screen)
screen.appendChild(scroller)
const src = window.location.hash.substring(1)
if (src.length === 43) {
window.location.hash = src + '='
}
if (src === '') {
controls.appendChild(await composer())
} if (src === 'settings') {
scroller.appendChild(settings)
}
const query = await bogbot.query(src)
if (query && query.length) {
adder(query, src, scroller)
} else if (src.length === 44) {
gossip(src)
}
window.onhashchange = function () {
screen.parentNode.removeChild(screen)
route(container)
}
}