make basic UI fully functional
This commit is contained in:
parent
674aad81fe
commit
979dfb9b08
50
ui/app.js
50
ui/app.js
@ -1,31 +1,43 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import Session from "../models/session.js";
|
|
||||||
import WbDb from "../data/db.js";
|
import WbDb from "../data/db.js";
|
||||||
import SessionRepo from "../data/session_repo.js";
|
import Shell from "./shell.js";
|
||||||
import SessionList from "./session_list.js";
|
|
||||||
|
|
||||||
export default class App {
|
export default class App {
|
||||||
#sessions = [];
|
#needsHandler = true;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
let db = WbDb.get();
|
WbDb.get().addEventListener(WbDb.EVENT_CHANGE, () => {
|
||||||
if (db.open)
|
if (this.#needsHandler) {
|
||||||
this.#dbReady();
|
WbDb.get().db.addEventListener("error", e => console.log(e));
|
||||||
else
|
this.#needsHandler = false;
|
||||||
db.addEventListener(WbDb.EVENT_CHANGE, this.#dbReady.bind(this));
|
}
|
||||||
}
|
m.redraw();
|
||||||
|
});
|
||||||
async #dbReady() {
|
|
||||||
this.#sessions = await SessionRepo.getAll();
|
|
||||||
m.redraw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
view() {
|
view() {
|
||||||
return m(SessionList, {
|
let db = WbDb.get();
|
||||||
models: this.#sessions,
|
|
||||||
onSelect: (key) => console.log("selected", key),
|
if (db.failed)
|
||||||
onNew: () => console.log("new"),
|
return m("[", [
|
||||||
});
|
m("h1", "Watterblock kann nicht geöffnet werden"),
|
||||||
|
m("p", "Die IndexedDB-Verbindung funktioniert gerade nicht"),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (db.blocked)
|
||||||
|
return m("[", [
|
||||||
|
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,8 +5,9 @@ import GameView from "./game.js";
|
|||||||
|
|
||||||
export default class SessionView {
|
export default class SessionView {
|
||||||
/** @param {{ attrs: { model: Session } }} param The session model to use. */
|
/** @param {{ attrs: { model: Session } }} param The session model to use. */
|
||||||
view({ attrs: { model } }) {
|
view({ attrs: { model, onDeselect } }) {
|
||||||
return m("article", [
|
return m("article", [
|
||||||
|
m("button", { onclick: () => onDeselect() }, "Zruck"),
|
||||||
model.games.map((g) => m(GameView, { model: g })),
|
model.games.map((g) => m(GameView, { model: g })),
|
||||||
model.currentGame !== null
|
model.currentGame !== null
|
||||||
? m(GameView, { model: model.currentGame })
|
? m(GameView, { model: model.currentGame })
|
||||||
|
|||||||
44
ui/shell.js
Normal file
44
ui/shell.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
import Session from "../models/session.js";
|
||||||
|
import SessionRepo from "../data/session_repo.js";
|
||||||
|
import SessionList from "./session_list.js";
|
||||||
|
import SessionView from "./session.js";
|
||||||
|
|
||||||
|
export default class Shell {
|
||||||
|
/** @type(?Session[]) */
|
||||||
|
#sessions = null;
|
||||||
|
/** @type(?Session) */
|
||||||
|
#currentSession = null;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
SessionRepo.getAll().then(ls => {
|
||||||
|
this.#sessions = ls;
|
||||||
|
m.redraw();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
view() {
|
||||||
|
if (this.#currentSession !== null)
|
||||||
|
return m(SessionView, {
|
||||||
|
model: this.#currentSession,
|
||||||
|
onDeselect: () => this.#currentSession = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.#sessions !== null)
|
||||||
|
return m(SessionList, {
|
||||||
|
models: this.#sessions,
|
||||||
|
onSelect: async (key) => {
|
||||||
|
this.#currentSession = await SessionRepo.get(key) ?? null;
|
||||||
|
},
|
||||||
|
onNew: async () => {
|
||||||
|
let session = new Session();
|
||||||
|
await SessionRepo.put(session);
|
||||||
|
this.#currentSession = session;
|
||||||
|
this.#sessions.splice(0, 0, session);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return m("p", "Wart kurz, i lad grad die Spiele…");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user