From 2b5a120bd3900d5cecbe355d336a4ea8d3a1b31a Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Wed, 12 Nov 2025 14:37:19 +0100 Subject: Prettified the code and cleaned up the light/dark mode --- court.mjs | 84 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 43 insertions(+), 41 deletions(-) (limited to 'court.mjs') diff --git a/court.mjs b/court.mjs index cb895f0..3a8e551 100644 --- a/court.mjs +++ b/court.mjs @@ -1,50 +1,52 @@ import { Manager } from "./utils.mjs"; class Court { - constructor(id, status) { - this.id = id; - this.status = typeof status !== 'undefined' ? status : true; - this.name = "Court " + (id + 1); - } - toggle() { - this.status = !this.status; - this.print(); - } - print() { - let status = this.status ? "active" : "inactive"; - console.log(this.name + " is currently " + status); - } - render() { - let type = this.status ? `class="button is-success"` : 'class="button is-danger"'; - return ``; - } + constructor(id, status) { + this.id = id; + this.status = typeof status !== "undefined" ? status : true; + this.name = "Court " + (id + 1); + } + toggle() { + this.status = !this.status; + this.print(); + } + print() { + let status = this.status ? "active" : "inactive"; + console.log(this.name + " is currently " + status); + } + render() { + let type = this.status + ? `class="button is-medium is-success"` + : 'class="button is-medium is-danger"'; + return ``; + } } export class CourtManager extends Manager { - maxCourtCount = 12; + maxCourtCount = 12; - constructor() { - super("court", []); - console.log("Loading court data."); - let data = JSON.parse(localStorage.getItem(this.description)); - if (data === null || data.length != this.maxCourtCount) { - console.log("Court data unavailable: " + data); - this.generate(); - return; - } - for (let i = 0; i < this.maxCourtCount; i++) { - this.listData.push(new Court(data[i].id, data[i].status)); - } - console.log("Loaded " + this.listData.length + " courts."); - this.render(); + constructor() { + super("court", []); + console.log("Loading court data."); + let data = JSON.parse(localStorage.getItem(this.description)); + if (data === null || data.length != this.maxCourtCount) { + console.log("Court data unavailable: " + data); + this.generate(); + return; + } + for (let i = 0; i < this.maxCourtCount; i++) { + this.listData.push(new Court(data[i].id, data[i].status)); } - generate() { - console.log("Generating court data."); - for (let i = 0; i < this.maxCourtCount; i++) { - this.listData.push(new Court(i)); - } - console.log("Generated data for " + this.listData.length + " courts"); - this.store(); - this.render(); + console.log("Loaded " + this.listData.length + " courts."); + this.render(); + } + generate() { + console.log("Generating court data."); + for (let i = 0; i < this.maxCourtCount; i++) { + this.listData.push(new Court(i)); } -} \ No newline at end of file + console.log("Generated data for " + this.listData.length + " courts"); + this.store(); + this.render(); + } +} -- cgit v1.3.1