60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
import Dataset from "./dataset.js";
|
|
|
|
const mainPage = document.getElementById("details");
|
|
const notFoundPage = document.getElementById("not-found");
|
|
|
|
const title = document.getElementById("title");
|
|
const rating = document.getElementById("rating");
|
|
const ratingText = document.getElementById("rating-text");
|
|
const shortDescription = document.getElementById("short-description");
|
|
const url = document.getElementById("url");
|
|
const date = document.getElementById("date");
|
|
const category = document.getElementById("category");
|
|
const license = document.getElementById("license");
|
|
const termsOfUse = document.getElementById("terms-of-use");
|
|
const fullDescription = document.getElementById("full-description");
|
|
|
|
const currentLocation = new URL(location.href);
|
|
if (currentLocation.searchParams.has("id")) {
|
|
const id = currentLocation.searchParams.get("id");
|
|
const response = await fetch(`${currentLocation.origin}/api/v1/datasets/id/${id}`);
|
|
console.dir(response);
|
|
|
|
if (response.ok) {
|
|
const data = await response.json();
|
|
const dataset = new Dataset(data);
|
|
console.dir(data, dataset);
|
|
const upvoteComponent = dataset.createUpvoteComponent();
|
|
|
|
title.innerText = dataset.title;
|
|
title.dataset.type = dataset.type.toLowerCase();
|
|
rating.value = dataset.rating;
|
|
ratingText.innerText = dataset.rating;
|
|
shortDescription.innerText = dataset.shortDescription;
|
|
url.href = dataset.url;
|
|
url.innerText = dataset.url;
|
|
mainPage.querySelector(".upvote").replaceWith(upvoteComponent);
|
|
|
|
date.datetime = dataset.date;
|
|
date.innerText = dataset.parseDate().toLocaleDateString(undefined, {
|
|
day: "numeric",
|
|
month: "long",
|
|
year: "numeric",
|
|
});
|
|
category.innerText = dataset.category.name;
|
|
category.dataset.id = dataset.category.id;
|
|
license.innerText = dataset.license;
|
|
termsOfUse.href = dataset.termsOfUse;
|
|
|
|
fullDescription.innerText = dataset.fullDescription;
|
|
|
|
mainPage.classList.remove("skeleton");
|
|
} else {
|
|
mainPage.classList.add("hidden");
|
|
notFoundPage.classList.remove("hidden");
|
|
}
|
|
} else {
|
|
mainPage.classList.add("hidden");
|
|
notFoundPage.classList.remove("hidden");
|
|
}
|