Skip to content

Commit

Permalink
feat: comparatif possible! yay!
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Jul 30, 2024
1 parent f2a5355 commit 775d045
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ <h1 id="header">
</h1>
<div id="body">
<div id="search-view">
<p id="ville">Sainte-Adèle</p>
<select name="ville" id="ville">
<option selected value="">Sainte-Adèle</option>
<option value="vsadm">Sainte-Agathe-des-Monts</option>
<option value="vss">Saint-Sauveur</option>
<option value="prevost">Prévost</option>
</select>
<form autocomplete="off" id="search-form" action="/">
<input id="search-box" type="search"
name="q" autofocus placeholder="Rechercher...">
Expand Down
19 changes: 15 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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`;
}
Expand Down

0 comments on commit 775d045

Please sign in to comment.