make basic ui remember one session
This commit is contained in:
parent
ad9f9035a1
commit
ff04d19185
27
ui/app.js
27
ui/app.js
@ -2,11 +2,36 @@
|
||||
|
||||
import Session from "../models/session.js";
|
||||
import SessionView from "./session.js";
|
||||
import WbDb from "../data/db.js";
|
||||
import SessionRepo from "../data/session_repo.js";
|
||||
|
||||
export default class App {
|
||||
#session = new Session();
|
||||
#session = null;
|
||||
|
||||
constructor() {
|
||||
let db = WbDb.get();
|
||||
if (db.open)
|
||||
this.#dbReady();
|
||||
else
|
||||
db.addEventListener(WbDb.EVENT_CHANGE, this.#dbReady.bind(this));
|
||||
}
|
||||
|
||||
async #dbReady() {
|
||||
let sessions = await SessionRepo.getAll();
|
||||
if (sessions.length === 0) {
|
||||
this.#session = new Session();
|
||||
SessionRepo.put(this.#session);
|
||||
} else
|
||||
this.#session = sessions[0];
|
||||
|
||||
m.redraw();
|
||||
}
|
||||
|
||||
view() {
|
||||
if (this.#session === null) {
|
||||
return m("p", "Warte auf Datenbank.");
|
||||
}
|
||||
|
||||
return m(SessionView, { model: this.#session });
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user