Add catalog search

This commit is contained in:
Dominic Ferrando
2025-04-21 00:00:50 -04:00
parent ffafc896e2
commit 65a3c155ce
2 changed files with 22 additions and 1 deletions
+18
View File
@@ -72,3 +72,21 @@ function resizeCatalogPreviewImgs() {
} }
} }
} }
function applyCatalogSearch() {
const searchText = $("catalogSearch").value.toLowerCase();
const posts = Array.from(document.querySelectorAll(".catalog-preview"));
for (const post of posts) {
const headerContent = post.querySelector("h1 a").textContent;
const bodyContent = post.querySelector("p").textContent;
const contentToSearch = (headerContent + "\n" + bodyContent).toLowerCase();
if (contentToSearch.search(searchText) === -1) {
post.style.display = "none";
}
else {
post.style.display = "";
}
}
}
+4 -1
View File
@@ -75,12 +75,15 @@ templ Board(board database.Board) {
<option selected value="small">Small</option> <option selected value="small">Small</option>
<option value="large">Large</option> <option value="large">Large</option>
</select> </select>
<input oninput="applyCatalogSearch()" id="catalogSearch" style="float: right;" placeholder="Search"/>
</div> </div>
<hr/> <hr/>
<div <div
hx-get={ fmt.Sprintf("/hx/%s/catalog", board.Slug) } hx-get={ fmt.Sprintf("/hx/%s/catalog", board.Slug) }
hx-trigger="load, refreshThreads from:body" hx-trigger="load, refreshThreads from:body"
_="on htmx:afterRequest call resizeCatalogPreviewImgs()" _="on htmx:afterRequest
call resizeCatalogPreviewImgs()
then call applyCatalogSearch()"
></div> ></div>
} }
} }