-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute.js
69 lines (62 loc) · 1.95 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { bogbot } from 'bogbot'
import { render } from './render.js'
import { h } from 'h'
import { composer } from './composer.js'
import { profile } from './profile.js'
import { makeRoom, gossip } from './gossip.js'
import { settings } from './settings.js'
export const route = async () => {
if (!window.location.hash) { window.location = '#'}
const src = window.location.hash.substring(1)
const scroller = h('div', {id: 'scroller'})
document.body.appendChild(scroller)
if (src === '') {
const controls = h('div', {id: 'controls'})
document.body.insertBefore(controls, scroller)
controls.appendChild(await composer())
const log = await bogbot.query()
if (log) {
log.forEach(async (msg) => {
const div = await render.hash(msg.hash)
scroller.insertBefore(div, scroller.firstChild)
})
}
}
if (src === 'settings') {
scroller.appendChild(await settings())
}
if (src.length === 44) {
try {
let got = false
const log = await bogbot.query(src)
if (log) {
log.forEach(async (msg) => {
got = true
const div = await render.hash(msg.hash, scroller)
scroller.insertBefore(div, scroller.firstChild)
})
}
if (!got) { await gossip(src)}
} catch (err) { console.log(err)}
} if (src.length > 44) {
const hash = await bogbot.hash(src)
const opened = await bogbot.open(src)
if (opened) {
await makeRoom(src.substring(0, 44))
await bogbot.add(src)
}
const check = document.getElementById(hash)
if (!check) {
const div = h('div', {id: hash}, [])
scroller.appendChild(div)
await render.blob(src)
}
}
}
window.onhashchange = async () => {
const scroller = document.getElementById('scroller')
const controls = document.getElementById('controls')
if (scroller) { scroller.parentNode.removeChild(scroller) }
if (controls) { controls.parentNode.removeChild(controls) }
await route()
}