started initial page display

This commit is contained in:
J-Klinke
2024-07-01 12:22:56 +02:00
parent e5a4b1186e
commit 3aa87d531b
3 changed files with 15 additions and 74 deletions

View File

@@ -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());