From eb2d6189a8bcc8a89f273c35d5914d3bf6fed08f Mon Sep 17 00:00:00 2001 From: J-Klinke Date: Tue, 25 Jun 2024 09:14:12 +0200 Subject: [PATCH] some code formatting, searchbar is now empty on reload --- src/main/resources/static/contentUtility.js | 5 ++--- src/main/resources/static/main.js | 13 +++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/resources/static/contentUtility.js b/src/main/resources/static/contentUtility.js index fc7b5b6..e2a032e 100644 --- a/src/main/resources/static/contentUtility.js +++ b/src/main/resources/static/contentUtility.js @@ -11,14 +11,13 @@ export function fetchQuery(fetchString) { } function parseContent(content) { - //TODO: method for parsing query results - console.log(content); + console.log(content); //TODO: remove if (content.length === 0) { searchSection.querySelector("#nothing-found ").classList.remove("hidden"); } else { searchSection.querySelector("#nothing-found").classList.add("hidden"); const datasets = content.map(dataset => new Dataset(dataset)); - console.log(datasets); + console.log(datasets); //TODO: remove Array.from(searchSection.querySelectorAll(".datasets .dataset")).forEach(e => e.remove()); for (const dataset of datasets) { searchSection.querySelector(".datasets").appendChild(dataset.createDatasetHTMLElement()); diff --git a/src/main/resources/static/main.js b/src/main/resources/static/main.js index 3cc733a..9753fad 100644 --- a/src/main/resources/static/main.js +++ b/src/main/resources/static/main.js @@ -2,7 +2,6 @@ import { fetchQuery } from "./contentUtility.js"; const apiEndpoint = "/api/v1/datasets"; const baseURL = location.origin; -const searchDelay = 500; const defaultPagingValue = 20; const lastQuery = { url: "", @@ -10,7 +9,7 @@ const lastQuery = { currentPage: 0 }; -// definition of all buttons +// definition of all buttons & sections const addButton = document.getElementById("add-btn"); const filterButton = document.getElementById("filter-btn"); const searchButton = document.getElementById("search-btn"); @@ -24,6 +23,7 @@ const mostLikedSection = document.getElementById("top"); // ID of the timeout, because we need to cancel it at some point export let searchBarTimeout; +const searchDelay = 500; // Event listeners addButton.addEventListener("click", () => { @@ -70,7 +70,7 @@ sortButton.addEventListener("change", () => { sort(sortString); }); -const upvoteButtonClickListener = e => { +const upvoteButtonClickListener = e => { const entryID = e.target.parentElement.parentElement.dataset.id; vote(entryID, true); }; @@ -117,11 +117,9 @@ function sort(sortString) { } else { query[1] = "desc"; } - let fetchURL = new URL(apiEndpoint, baseURL); fetchURL.searchParams.append("sort", query[0]); fetchURL.searchParams.append("direction", query[1]); - console.log(fetchURL); // TODO: remove fetchQuery(fetchURL); } @@ -131,7 +129,6 @@ function vote(entryID, up) { `${apiEndpoint}/id/${entryID}/${up ? "up" : "down"}vote`, baseURL, ); - console.log(fetchURL); // TODO: remove fetch(fetchURL); } @@ -139,3 +136,7 @@ function vote(entryID, up) { function incrementPageCount() { lastQuery.currentPage++; } + +window.onload = function () { + document.getElementById("search-entry").value = ""; +}