diff options
| author | Petri Hienonen <petri.hienonen@gmail.com> | 2025-11-13 18:12:17 +0200 |
|---|---|---|
| committer | Petri Hienonen <petri.hienonen@gmail.com> | 2025-11-13 18:12:17 +0200 |
| commit | e4fdd8457d2d320eea502f0801fc22eceb8947b1 (patch) | |
| tree | 110530c498b276085bb409a537a3e2174d53d435 /app/main.js | |
| parent | 2113f8269423932fa76ae4f822f77a07dd703266 (diff) | |
| download | housing-e4fdd8457d2d320eea502f0801fc22eceb8947b1.tar.zst | |
Nothing
Diffstat (limited to 'app/main.js')
| -rw-r--r-- | app/main.js | 47 |
1 files changed, 16 insertions, 31 deletions
diff --git a/app/main.js b/app/main.js index f4227d9..9abb300 100644 --- a/app/main.js +++ b/app/main.js @@ -6,20 +6,14 @@ import { MapEl } from "map"; import { AreaParam, Collection, - District, Filters, House, HouseParameter, ScoringEngine, - StatisticalArea, - TrainStation, - TrainTracks, Weights, } from "models"; export class App { - /** @type {House[]} */ - #houses = []; /** @type {Collection|null} */ collection = null; /** @type {House[]} */ @@ -36,8 +30,6 @@ export class App { #sidebar; /** @type {Modal|null} */ #modal = null; - /** @type {boolean} */ - #persistent = false; /** @type {HouseParameter} */ #houseParameter = HouseParameter.price; /** @type {AreaParam} */ @@ -58,7 +50,7 @@ export class App { this.#filters, this.#weights, () => { - this.#filtered = this.#houses.filter((h) => h.matchesFilters(this.#filters)); + this.#filtered = this.collection?.houses.filter((h) => h.matchesFilters(this.#filters)); const filteredIds = this.#filtered.map((h) => h.id); this.#map.updateHouseVisibility(filteredIds); @@ -70,7 +62,7 @@ export class App { if (key in this.#weights) { this.#weights[/** @type {keyof Weights} */ (key)] = value; } - App.#recalculateScores(this.#houses, this.#weights); + App.#recalculateScores(this.collection?.houses, this.#weights); this.#map.updateHousesColor(this.#houseParameter); const stats = App.#getStats(this.#filtered); this.#stats.replaceWith(stats); @@ -156,10 +148,9 @@ export class App { * @param {boolean} persistent */ #showHouseModal(houseId, persistent) { - const house = this.#houses.find((h) => h.id === houseId); + const house = this.collection?.houses.find((h) => h.id === houseId); if (!house) return; - this.#persistent = persistent; this.#map.setModalPersistence(persistent); // Hide existing modal @@ -179,7 +170,6 @@ export class App { }, () => { this.#modal = null; - this.#persistent = false; this.#map.setModalPersistence(false); this.#map.clearModalTimer(); }, @@ -202,7 +192,7 @@ export class App { this.#filtered = this.collection.houses.slice(); this.#map.initialize(this.collection, this.#houseParameter, this.#areaParameter); - this.#sidebar.updateDistricts(this.#houses); + this.#sidebar.updateDistricts(this.collection.houses); this.#sidebar.setAreaColorParameter(this.#areaParameter); const stats = App.#getStats(this.#filtered); @@ -229,8 +219,19 @@ export class App { * @param {House[]} filtered */ static #getStats(filtered) { - const stats = Dom.div( + return Dom.div( new DomOptions({ + children: [ + Dom.strong(filtered.length.toString()), + document.createTextNode(" houses shown • Average score: "), + Dom.strong( + (filtered.length + ? Math.round(filtered.reduce((s, h) => s + h.scores.current, 0) / filtered.length) + : 0 + ).toString(), + ), + document.createTextNode(" • Use weights sliders to adjust scoring"), + ], id: "stats", styles: { background: "#fff", @@ -241,22 +242,6 @@ export class App { }, }), ); - const countStrong = Dom.strong(filtered.length.toString()); - const avgStrong = Dom.strong( - (filtered.length - ? Math.round(filtered.reduce((s, h) => s + h.scores.current, 0) / filtered.length) - : 0 - ).toString(), - ); - - // Append all elements - stats.append( - countStrong, - document.createTextNode(" houses shown • Average score: "), - avgStrong, - document.createTextNode(" • Use weights sliders to adjust scoring"), - ); - return stats; } } |
