1
0

basic session selector

This commit is contained in:
Adrian Wannenmacher 2026-02-17 21:31:33 +01:00
parent 353c441722
commit a961c87e96
Signed by: tfld
GPG Key ID: 19D986ECB1E492D5
2 changed files with 30 additions and 14 deletions

View File

@ -1,12 +1,12 @@
"use strict"; "use strict";
import Session from "../models/session.js"; import Session from "../models/session.js";
import SessionView from "./session.js";
import WbDb from "../data/db.js"; import WbDb from "../data/db.js";
import SessionRepo from "../data/session_repo.js"; import SessionRepo from "../data/session_repo.js";
import SessionList from "./session_list.js";
export default class App { export default class App {
#session = null; #sessions = [];
constructor() { constructor() {
let db = WbDb.get(); let db = WbDb.get();
@ -17,21 +17,15 @@ export default class App {
} }
async #dbReady() { async #dbReady() {
let sessions = await SessionRepo.getAll(); this.#sessions = await SessionRepo.getAll();
if (sessions.length === 0) {
this.#session = new Session();
SessionRepo.put(this.#session);
} else
this.#session = sessions[0];
m.redraw(); m.redraw();
} }
view() { view() {
if (this.#session === null) { return m(SessionList, {
return m("p", "Warte auf Datenbank."); models: this.#sessions,
} onSelect: (key) => console.log("selected", key),
onNew: () => console.log("new"),
return m(SessionView, { model: this.#session }); });
} }
} }

22
ui/session_list.js Normal file
View File

@ -0,0 +1,22 @@
"use strict";
import Session from "../models/session.js";
export default class SessionList {
/** @param {{ attrs: { models: Session[] } }} param The sessions to show. */
view({attrs: { models, onSelect, onNew } }) {
return m("section", [
m("button", { onclick: () => onNew() }, "Neie Session"),
m("ol", [
models.map((s) => m("li", [
m("button", { onclick: () => onSelect(s.id) }, [
m("p", s.ourTeam !== "" ? s.ourTeam : "Unbnannts Team"),
m("p", s.theirTeam !== "" ? s.theirTeam : "Unbnannts Team"),
m("p", "•".repeat(s.result.ourPoints)),
m("p", "•".repeat(s.result.theirPoints)),
])
]))
])
]);
}
}