refactor to allow use of routing
This commit is contained in:
parent
36d6a9ed9b
commit
b9ed3ed37f
@ -7,16 +7,13 @@
|
|||||||
<title>Watterblock</title>
|
<title>Watterblock</title>
|
||||||
<link rel="stylesheet" href="/vendored/normalize-8.0.1.css">
|
<link rel="stylesheet" href="/vendored/normalize-8.0.1.css">
|
||||||
<link rel="stylesheet" href="/style.css">
|
<link rel="stylesheet" href="/style.css">
|
||||||
<script src="/vendored/mithril-2.3.8.js" defer></script>
|
|
||||||
<script type="module">
|
<script type="module">
|
||||||
// initialize DB early
|
// initialize DB early
|
||||||
import WbDb from "/data/db.js";
|
import WbDb from "/data/db.js";
|
||||||
WbDb.get();
|
WbDb.get();
|
||||||
|
|
||||||
// mount app
|
|
||||||
import App from "/ui/app.js";
|
|
||||||
m.mount(document.body, App);
|
|
||||||
</script>
|
</script>
|
||||||
|
<script src="/vendored/mithril-2.3.8.js" defer></script>
|
||||||
|
<script src="/index.js" type="module"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
13
index.js
Normal file
13
index.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
import Layout from "/ui/layout.js";
|
||||||
|
import BaseView from "/ui/base_view.js";
|
||||||
|
|
||||||
|
m.route.prefix = "";
|
||||||
|
m.route(document.body, "/", {
|
||||||
|
"/": {
|
||||||
|
render: function() {
|
||||||
|
return m(Layout, m(BaseView));
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
43
ui/app.js
43
ui/app.js
@ -1,43 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
import WbDb from "/data/db.js";
|
|
||||||
import Shell from "/ui/shell.js";
|
|
||||||
|
|
||||||
export default class App {
|
|
||||||
#needsHandler = true;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
WbDb.get().addEventListener(WbDb.EVENT_CHANGE, () => {
|
|
||||||
if (this.#needsHandler) {
|
|
||||||
WbDb.get().db.addEventListener("error", e => console.log(e));
|
|
||||||
this.#needsHandler = false;
|
|
||||||
}
|
|
||||||
m.redraw();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
view() {
|
|
||||||
let db = WbDb.get();
|
|
||||||
|
|
||||||
if (db.failed)
|
|
||||||
return m.fragment([
|
|
||||||
m("h1", "Watterblock kann nicht geöffnet werden"),
|
|
||||||
m("p", "Die IndexedDB-Verbindung funktioniert gerade nicht"),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (db.blocked)
|
|
||||||
return m.fragment([
|
|
||||||
m("h1", "Watterblock muss warten"),
|
|
||||||
m("p",
|
|
||||||
"Bitte schließe alle anderen Tabs, in denen der Watterblock " +
|
|
||||||
"geöffnet ist"
|
|
||||||
),
|
|
||||||
m("p", "Die Spieledatenbank muss aktualisiert werden."),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!db.open)
|
|
||||||
return m("p", "Öffne Datenbank, bitte warten…");
|
|
||||||
|
|
||||||
return m(Shell);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -5,7 +5,7 @@ import SessionRepo from "/data/session_repo.js";
|
|||||||
import SessionList from "/ui/session_list.js";
|
import SessionList from "/ui/session_list.js";
|
||||||
import SessionView from "/ui/session.js";
|
import SessionView from "/ui/session.js";
|
||||||
|
|
||||||
export default class Shell {
|
export default class BaseView {
|
||||||
/** @type(?Session[]) */
|
/** @type(?Session[]) */
|
||||||
#sessions = null;
|
#sessions = null;
|
||||||
/** @type(?Session) */
|
/** @type(?Session) */
|
||||||
50
ui/layout.js
Normal file
50
ui/layout.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
import WbDb from "/data/db.js";
|
||||||
|
|
||||||
|
export default class Layout {
|
||||||
|
#db = WbDb.get();
|
||||||
|
#dbErrorsHandled = false;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.#db.addEventListener(WbDb.EVENT_CHANGE, () => {
|
||||||
|
if (!this.#dbErrorsHandled) {
|
||||||
|
this.#db.addEventListener("error", this.#handleDbError.bind(this));
|
||||||
|
this.#dbErrorsHandled = true;
|
||||||
|
}
|
||||||
|
m.redraw();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.#db.open && !this.#dbErrorsHandled) {
|
||||||
|
this.#db.addEventListener("error", this.#handleDbError.bind(this));
|
||||||
|
this.#dbErrorsHandled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#handleDbError(error) {
|
||||||
|
console.error("database error", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
view(vnode) {
|
||||||
|
if (this.#db.failed)
|
||||||
|
return m.fragment([
|
||||||
|
m("h1", "Watterblock kann nicht geöffnet werden"),
|
||||||
|
m("p", "Die IndexedDB-Verbindung funktioniert gerade nicht"),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (this.#db.blocked)
|
||||||
|
return m.fragment([
|
||||||
|
m("h1", "Watterblock muss warten"),
|
||||||
|
m("p",
|
||||||
|
"Bitte schließe alle anderen Tabs, in denen der Watterblock " +
|
||||||
|
"geöffnet ist"
|
||||||
|
),
|
||||||
|
m("p", "Die Spieledatenbank muss aktualisiert werden."),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!this.#db.open)
|
||||||
|
return m("p", "Öffne Datenbank, bitte warten…");
|
||||||
|
|
||||||
|
return m("main", vnode.children);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user