From e2c24a2593216e09f4ecfabd18f408be7ef676c3 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Sat, 14 Oct 2023 13:07:30 +0100 Subject: [PATCH] accounts: add "not results found" screen --- html/admin.html | 10 +++++++++- ts/modules/accounts.ts | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/html/admin.html b/html/admin.html index 4792436..48818a9 100644 --- a/html/admin.html +++ b/html/admin.html @@ -645,7 +645,7 @@ - +
@@ -708,6 +708,14 @@ +
+
+ {{ .strings.noResultsFound }} + +
+
diff --git a/ts/modules/accounts.ts b/ts/modules/accounts.ts index f4ca0b0..34595ad 100644 --- a/ts/modules/accounts.ts +++ b/ts/modules/accounts.ts @@ -946,6 +946,8 @@ export class accountsList { } } + private _notFoundPanel: HTMLElement = document.getElementById("accounts-not-found"); + search = (query: String): string[] => { console.log(this._queries); this._filterArea.textContent = ""; @@ -2021,17 +2023,25 @@ export class accountsList { this._inSearch = true; // this.setVisibility(this.search(query), true); } - this.setVisibility(this.search(query), true); + const results = this.search(query); + this.setVisibility(results, true); this._checkCheckCount(); this.showHideSearchOptionsHeader(); + if (results.length == 0) { + this._notFoundPanel.classList.remove("unfocused"); + } else { + this._notFoundPanel.classList.add("unfocused"); + } }; this._search.oninput = onchange; - const clearSearchButton = document.getElementById("accounts-search-clear") as HTMLSpanElement; - clearSearchButton.addEventListener("click", () => { - this._search.value = ""; - onchange(); - }); + const clearSearchButtons = Array.from(document.getElementsByClassName("accounts-search-clear")) as Array; + for (let b of clearSearchButtons) { + b.addEventListener("click", () => { + this._search.value = ""; + onchange(); + }); + } this._announceTextarea.onkeyup = this.loadPreview; addDiscord = newDiscordSearch(window.lang.strings("linkDiscord"), window.lang.strings("searchDiscordUser"), window.lang.strings("add"), (user: DiscordUser, id: string) => { @@ -2084,8 +2094,15 @@ export class accountsList { // console.log("ordering by", event.detail, ": ", this._ordering); if (!(this._inSearch)) { this.setVisibility(this._ordering, true); + this._notFoundPanel.classList.add("unfocused"); } else { - this.setVisibility(this.search(this._search.value), true); + const results = this.search(this._search.value); + this.setVisibility(results, true); + if (results.length == 0) { + this._notFoundPanel.classList.remove("unfocused"); + } else { + this._notFoundPanel.classList.add("unfocused"); + } } this.showHideSearchOptionsHeader(); }); @@ -2195,8 +2212,15 @@ export class accountsList { this._ordering = this._columns[this._activeSortColumn].sort(this._users); if (!(this._inSearch)) { this.setVisibility(this._ordering, true); + this._notFoundPanel.classList.add("unfocused"); } else { - this.setVisibility(this.search(this._search.value), true); + const results = this.search(this._search.value); + if (results.length == 0) { + this._notFoundPanel.classList.remove("unfocused"); + } else { + this._notFoundPanel.classList.add("unfocused"); + } + this.setVisibility(results, true); } this._checkCheckCount(); }