improved searchBar functionality:

on page reload, it now displays the query fitting to the entered string
This commit is contained in:
J-Klinke
2024-06-25 09:44:01 +02:00
parent eb2d6189a8
commit e47edf3cf2

View File

@@ -41,16 +41,7 @@ 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");
}
updateSections();
clearTimeout(searchBarTimeout);
searchBarTimeout = setTimeout(() => {
const searchString = searchBar.value;
@@ -137,6 +128,21 @@ function incrementPageCount() {
lastQuery.currentPage++;
}
window.onload = function () {
document.getElementById("search-entry").value = "";
function updateSections() {
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");
}
}
window.onload = function () {
updateSections();
if (searchBar.value !== "") {
search(searchBar.value);
}
}