aboutsummaryrefslogtreecommitdiffstats
path: root/app/main.js
diff options
context:
space:
mode:
authorPetri Hienonen <petri.hienonen@gmail.com>2025-11-08 23:06:17 +0200
committerPetri Hienonen <petri.hienonen@gmail.com>2025-11-08 23:06:17 +0200
commit81cb28a961520dd8ff29af6aee67814804e07263 (patch)
treec9763e9edb824e36f265c8739d2ba6d413e725da /app/main.js
parent277ffe2cab8c711427b979fbc057c7d04932398e (diff)
downloadhousing-81cb28a961520dd8ff29af6aee67814804e07263.tar.zst
Separate modal
Diffstat (limited to '')
-rw-r--r--app/main.js71
1 files changed, 24 insertions, 47 deletions
diff --git a/app/main.js b/app/main.js
index 3c9b637..c8a10a3 100644
--- a/app/main.js
+++ b/app/main.js
@@ -1,4 +1,5 @@
-import { Dom, DomOptions, Widgets } from "dom";
+// main.js
+import { Dom, DomOptions, Modal, Widgets } from "dom";
import { ColorParameter, MapEl } from "map";
import {
DataProvider,
@@ -32,10 +33,8 @@ export class App {
#stats;
/** @type {HTMLElement} */
#controls;
- /** @type {HTMLDialogElement|null} */
+ /** @type {Modal|null} */
#modal = null;
- /** @type {number | undefined} */
- #modalTimer = undefined;
/** @type {boolean} */
#persistent = false;
/** @type {string} */
@@ -80,7 +79,7 @@ export class App {
onHouseClick: (houseId, persistent) => this.#showHouseModal(houseId, persistent),
onHouseHover: (houseId, hide) => {
if (hide) {
- this.#hideModal();
+ this.#modal?.hide();
} else {
this.#showHouseModal(houseId, false);
}
@@ -409,11 +408,12 @@ export class App {
this.#map.setModalPersistence(persistent);
}
- // Remove existing modal
- this.#modal?.remove();
+ // Hide existing modal
+ this.#modal?.hide();
- // Create new modal
- this.#modal = Widgets.buildModal(
+ this.#modal = new Modal(
+ house,
+ persistent,
{
left: "auto",
maxHeight: "80vh",
@@ -423,47 +423,24 @@ export class App {
transform: "translateY(-50%)",
width: "90%",
},
-
- () => this.#hideModal(),
+ () => {
+ this.#modal = null;
+ this.#persistent = false;
+ if (this.#map) {
+ this.#map.setModalPersistence(false);
+ this.#map.clearModalTimer();
+ }
+ },
+ () => {
+ if (this.#map) {
+ this.#map.clearModalTimer();
+ }
+ },
);
- Object.assign(this.#modal.style);
- // Add hover grace period listeners
- this.#modal.addEventListener("mouseenter", () => {
- clearTimeout(this.#modalTimer);
- if (this.#map) {
- this.#map.clearModalTimer();
- }
- });
-
- this.#modal.addEventListener("mouseleave", () => {
- if (!this.#persistent) {
- this.#modalTimer = setTimeout(() => this.#hideModal(), 200);
- }
- });
-
- this.#modal.appendChild(Widgets.buildModalContent(house));
- document.body.appendChild(this.#modal);
-
- if (persistent) {
- this.#modal.showModal();
- } else {
- this.#modal.show();
- }
+ document.body.appendChild(this.#modal.render());
+ this.#modal.show();
}
-
- #hideModal() {
- this.#modal?.close();
- this.#modal?.remove();
- this.#modal = null;
- this.#persistent = false;
- clearTimeout(this.#modalTimer);
- if (this.#map) {
- this.#map.setModalPersistence(false);
- this.#map.clearModalTimer();
- }
- }
-
/**
* Load data and initialize application
* @param {HTMLElement} loading