search nw displays the search results.

other section are being hidden in the case of a search and vice versa.
a 'nothing found' div was implemented
This commit is contained in:
J-Klinke
2024-06-24 17:03:47 +02:00
parent 43d3ff17d5
commit d96da1b1e7
7 changed files with 137 additions and 19 deletions

View File

@@ -2,6 +2,7 @@ import { fetchQuery } from "./contentUtility.js";
const apiEndpoint = "/api/v1/datasets";
const baseURL = location.origin;
const searchDelay = 500;
const defaultPagingValue = 20;
const lastQuery = {
url: "",
@@ -17,6 +18,9 @@ const searchBar = document.getElementById("search-entry");
const sortButton = document.getElementById("sort-btn");
const upvoteButtons = document.getElementsByClassName("upvote-btn");
const downvoteButtons = document.getElementsByClassName("downvote-btn");
export const searchSection = document.getElementById("search");
const recentSection = document.getElementById("recents");
const mostLikedSection = document.getElementById("top");
// ID of the timeout, because we need to cancel it at some point
export let searchBarTimeout;
@@ -37,11 +41,21 @@ searchButton.addEventListener("click", () => {
});
searchBar.addEventListener("input", () => {
if (searchBar.value === "") {
searchSection.classList.add("hidden");
recentSection.classList.remove("hidden");
mostLikedSection.classList.remove("hidden");
} else {
searchSection.classList.remove("hidden");
recentSection.classList.add("hidden");
mostLikedSection.classList.add("hidden");
}
clearTimeout(searchBarTimeout);
searchBarTimeout = setTimeout(() => {
const searchString = searchBar.value;
search(searchString);
}, 1000);
}, searchDelay);
});
searchBar.addEventListener('keypress', function (e) {