some code formatting,

searchbar is now empty on reload
This commit is contained in:
J-Klinke
2024-06-25 09:14:12 +02:00
parent d96da1b1e7
commit eb2d6189a8
2 changed files with 9 additions and 9 deletions

View File

@@ -11,14 +11,13 @@ export function fetchQuery(fetchString) {
} }
function parseContent(content) { function parseContent(content) {
//TODO: method for parsing query results console.log(content); //TODO: remove
console.log(content);
if (content.length === 0) { if (content.length === 0) {
searchSection.querySelector("#nothing-found ").classList.remove("hidden"); searchSection.querySelector("#nothing-found ").classList.remove("hidden");
} else { } else {
searchSection.querySelector("#nothing-found").classList.add("hidden"); searchSection.querySelector("#nothing-found").classList.add("hidden");
const datasets = content.map(dataset => new Dataset(dataset)); 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()); Array.from(searchSection.querySelectorAll(".datasets .dataset")).forEach(e => e.remove());
for (const dataset of datasets) { for (const dataset of datasets) {
searchSection.querySelector(".datasets").appendChild(dataset.createDatasetHTMLElement()); searchSection.querySelector(".datasets").appendChild(dataset.createDatasetHTMLElement());

View File

@@ -2,7 +2,6 @@ import { fetchQuery } from "./contentUtility.js";
const apiEndpoint = "/api/v1/datasets"; const apiEndpoint = "/api/v1/datasets";
const baseURL = location.origin; const baseURL = location.origin;
const searchDelay = 500;
const defaultPagingValue = 20; const defaultPagingValue = 20;
const lastQuery = { const lastQuery = {
url: "", url: "",
@@ -10,7 +9,7 @@ const lastQuery = {
currentPage: 0 currentPage: 0
}; };
// definition of all buttons // definition of all buttons & sections
const addButton = document.getElementById("add-btn"); const addButton = document.getElementById("add-btn");
const filterButton = document.getElementById("filter-btn"); const filterButton = document.getElementById("filter-btn");
const searchButton = document.getElementById("search-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 // ID of the timeout, because we need to cancel it at some point
export let searchBarTimeout; export let searchBarTimeout;
const searchDelay = 500;
// Event listeners // Event listeners
addButton.addEventListener("click", () => { addButton.addEventListener("click", () => {
@@ -117,11 +117,9 @@ function sort(sortString) {
} else { } else {
query[1] = "desc"; query[1] = "desc";
} }
let fetchURL = new URL(apiEndpoint, baseURL); let fetchURL = new URL(apiEndpoint, baseURL);
fetchURL.searchParams.append("sort", query[0]); fetchURL.searchParams.append("sort", query[0]);
fetchURL.searchParams.append("direction", query[1]); fetchURL.searchParams.append("direction", query[1]);
console.log(fetchURL); // TODO: remove console.log(fetchURL); // TODO: remove
fetchQuery(fetchURL); fetchQuery(fetchURL);
} }
@@ -131,7 +129,6 @@ function vote(entryID, up) {
`${apiEndpoint}/id/${entryID}/${up ? "up" : "down"}vote`, `${apiEndpoint}/id/${entryID}/${up ? "up" : "down"}vote`,
baseURL, baseURL,
); );
console.log(fetchURL); // TODO: remove console.log(fetchURL); // TODO: remove
fetch(fetchURL); fetch(fetchURL);
} }
@@ -139,3 +136,7 @@ function vote(entryID, up) {
function incrementPageCount() { function incrementPageCount() {
lastQuery.currentPage++; lastQuery.currentPage++;
} }
window.onload = function () {
document.getElementById("search-entry").value = "";
}