basic session selector
This commit is contained in:
parent
353c441722
commit
a961c87e96
22
ui/app.js
22
ui/app.js
@ -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
22
ui/session_list.js
Normal 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)),
|
||||||
|
])
|
||||||
|
]))
|
||||||
|
])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user