From 775d045f569a12acb956ba56ef430b07d205b1eb Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Mon, 29 Jul 2024 22:04:14 -0400 Subject: [PATCH] feat: comparatif possible! yay! --- index.html | 7 ++++++- src/main.ts | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 49162f4..10eea2b 100644 --- a/index.html +++ b/index.html @@ -19,7 +19,12 @@

-

Sainte-Adèle

+
diff --git a/src/main.ts b/src/main.ts index 869e0c5..b5b61bb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -28,6 +28,7 @@ class App { search_box: HTMLInputElement; document_view: HTMLElement; search_results: HTMLElement; + ville: HTMLSelectElement; media_query: MediaQueryList; index: lunr.Index | null = null; textes: Textes | null = null; @@ -49,6 +50,8 @@ class App { // Find the appropriate index if required (somewhat hacky) this.alexi_url = ALEXI_URL; this.base_url = BASE_URL; + // Drop-down for towns + this.ville = document.getElementById("ville")! as HTMLSelectElement; if (window.location.pathname != BASE_URL) { const url = window.location.pathname.substring(BASE_URL.length).replace(/\/$/, "").replace(/index.html$/, ""); console.log(window.location.pathname, BASE_URL, url); @@ -57,16 +60,15 @@ class App { const idx = url.indexOf("/"); const name = (idx == -1) ? url : url.substring(0, idx); let other_ville = true; - const ville = document.getElementById("ville")!; switch (name) { case "vsadm": - ville.textContent = "Sainte-Agathe-des-Monts"; + this.ville.value = "vsadm"; break; case "vss": - ville.textContent = "Saint-Sauveur"; + this.ville.value = "vss"; break; case "prevost": - ville.textContent = "Prévost"; + this.ville.value = "prevost"; break; default: other_ville = false; @@ -78,6 +80,15 @@ class App { console.log("base_url", this.base_url); console.log("alexi_url", this.alexi_url); } + // Set up change listener *after* assigning :) + this.ville.addEventListener("change", _ => { + let new_url = BASE_URL + this.ville.value; + const urlParams = new URLSearchParams(window.location.search); + const query = urlParams.get("q"); + if (query !== null) + new_url += "?q=" + encodeURIComponent(query); + window.location.assign(new_url); + }); this.index_url = `${this.alexi_url}/_idx/index.json`; this.textes_url = `${this.alexi_url}/_idx/textes.json`; }