From 3aa87d531ba5f1dec3d206435c0cce0977afd6bd Mon Sep 17 00:00:00 2001 From: J-Klinke Date: Mon, 1 Jul 2024 12:22:56 +0200 Subject: [PATCH] started initial page display --- src/main/resources/static/contentUtility.js | 1 - src/main/resources/static/main.js | 15 +++++ src/main/resources/templates/index.html | 73 --------------------- 3 files changed, 15 insertions(+), 74 deletions(-) diff --git a/src/main/resources/static/contentUtility.js b/src/main/resources/static/contentUtility.js index e2a032e..2f14c10 100644 --- a/src/main/resources/static/contentUtility.js +++ b/src/main/resources/static/contentUtility.js @@ -11,7 +11,6 @@ export function fetchQuery(fetchString) { } function parseContent(content) { - console.log(content); //TODO: remove if (content.length === 0) { searchSection.querySelector("#nothing-found ").classList.remove("hidden"); } else { diff --git a/src/main/resources/static/main.js b/src/main/resources/static/main.js index 507be85..65a8ef8 100644 --- a/src/main/resources/static/main.js +++ b/src/main/resources/static/main.js @@ -1,4 +1,5 @@ import {fetchQuery} from "./contentUtility.js"; +import Dataset from "./dataset"; const apiEndpoint = "/api/v1/datasets"; const baseURL = location.origin; @@ -106,6 +107,7 @@ function getSearchQuery() { let searchString = searchBar.value; return (searchString.length === 0 ? "%" : (searchString + "%")); } + function getSortQuery() { let sortString = sortButton.value.toLowerCase().split(" "); if (sortString[1] === "a-z" || sortString[1] === "↑" || sortString[1] === "oldest-newest") { @@ -181,8 +183,21 @@ function fetchCategories() { }); } +function fetchInitialEntries() { + let topVotedQueryURL = new URL(apiEndpoint + "/search" + baseURL); + topVotedQueryURL.searchParams.append("sort", getSortQuery()[0]); + topVotedQueryURL.searchParams.append("direction", getSortQuery()[1]); + topVotedQueryURL.searchParams.append("size", "1"); + fetch(topVotedQueryURL) + .then(resp => resp.json()) + .then((data) => { + document.querySelector("#top .datasets").appendChild(new Dataset(data[0]).createDatasetHTMLElement()); + }); +} + window.onload = function () { fetchCategories(); + fetchInitialEntries(); updateSections(); if (searchBar.value !== "") { fetchQuery(createQuery()); diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index aa5709b..23ee989 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -62,84 +62,11 @@

Recently added:

Most Liked: