started implementing local storage
This commit is contained in:
@@ -5,10 +5,10 @@ const apiEndpoint = "/api/v1/datasets";
|
||||
const baseURL = location.origin;
|
||||
const defaultPagingValue = 20;
|
||||
export const lastQuery = {
|
||||
url: "",
|
||||
totalPages: 0,
|
||||
currentPage: 0
|
||||
};
|
||||
export const votedIDs = new Map;
|
||||
|
||||
// definition of all buttons & sections
|
||||
const addButton = document.getElementById("add-btn");
|
||||
@@ -146,13 +146,18 @@ export function vote(entryID, up) {
|
||||
.then(resp => resp.json())
|
||||
.then((data) => {
|
||||
console.log(data.upvotes); // TODO: remove, check einbauen: data.id === entryID?
|
||||
let dataset = document.querySelector('[data-id= ' + CSS.escape(entryID) + ']')
|
||||
dataset.querySelector("span").innerText = data.upvotes;
|
||||
});
|
||||
}
|
||||
let dataSet = document.querySelector('[data-id= ' + CSS.escape(entryID) + ']')
|
||||
dataSet.querySelector("span").innerText = data.upvotes;
|
||||
|
||||
let votedButton = dataSet.querySelector(up? ".upvote-btn":".downvote-btn");
|
||||
votedButton.classList.add("isVoted");
|
||||
votedButton.disabled = true;
|
||||
let notVotedButton = dataSet.querySelector(up? ".downvote-btn":".upvote-btn");
|
||||
notVotedButton.style.visibility = "hidden";
|
||||
console.log(dataSet.getAttribute("data-id"));
|
||||
votedIDs.set(dataSet.getAttribute("data-id"), up);
|
||||
});
|
||||
|
||||
function incrementPageCount() {
|
||||
lastQuery.currentPage++;
|
||||
}
|
||||
|
||||
// updates the page display. If no query is present, the initial page is shown, otherwise the search results.
|
||||
@@ -197,6 +202,7 @@ function fetchInitialEntries() {
|
||||
.then((data) => {
|
||||
const datasets = data.content.map(dataset => new Dataset(dataset));
|
||||
for (const dataset of datasets) {
|
||||
//dataSets.add(dataset);
|
||||
document.querySelector("#recents .datasets").appendChild(dataset.createDatasetHTMLElement());
|
||||
}
|
||||
});
|
||||
@@ -208,8 +214,9 @@ function fetchInitialEntries() {
|
||||
fetch(topVotedQueryURL)
|
||||
.then(resp => resp.json())
|
||||
.then((data) => {
|
||||
document.querySelector("#top .datasets")
|
||||
.appendChild(new Dataset(data.content[0]).createDatasetHTMLElement());
|
||||
let dataset = new Dataset(data.content[0]);
|
||||
//dataSets.add(dataset);
|
||||
document.querySelector("#top .datasets").appendChild(dataset.createDatasetHTMLElement());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user