upvoting suppression by local storage now works, there is a bug however with the entries loaded o startup
This commit is contained in:
parent
20eda5931a
commit
6d34b8c388
@ -1,4 +1,4 @@
|
||||
import {searchBarTimeout, searchSection, lastQuery, votedIDs} from "./main.js"
|
||||
import {searchBarTimeout, searchSection, lastQuery} from "./main.js"
|
||||
import Dataset from "./dataset.js"
|
||||
|
||||
export function fetchQuery(fetchString, clearResults) {
|
||||
@ -24,12 +24,9 @@ function parseContent(content, clearResults) {
|
||||
Array.from(searchSection.querySelectorAll(".datasets .dataset")).forEach(e => e.remove());
|
||||
}
|
||||
for (const dataset of datasets) {
|
||||
if (votedIDs.has(dataset.getID())) {
|
||||
searchSection.querySelector(".datasets").appendChild(dataset.createDatasetHTMLElement(false,));
|
||||
} else {
|
||||
searchSection.querySelector(".datasets").appendChild(dataset.createDatasetHTMLElement());
|
||||
}
|
||||
console.log(dataset) //TODO: remove
|
||||
searchSection.querySelector(".datasets")
|
||||
.appendChild(dataset.createDatasetHTMLElement(dataset.getID()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { vote } from "./main.js";
|
||||
import { vote, votedIDs } from "./main.js";
|
||||
|
||||
export default class Dataset {
|
||||
#abstract;
|
||||
@ -29,18 +29,20 @@ export default class Dataset {
|
||||
this.#votes = votes;
|
||||
}
|
||||
|
||||
createDatasetHTMLElement(votable, isUpVoted) {
|
||||
createDatasetHTMLElement(entryID) {
|
||||
let template = document.querySelector("#dataset-template");
|
||||
const clone = template.content.cloneNode(true);
|
||||
clone.querySelector(".dataset").dataset.id = this.#id;
|
||||
clone.querySelector("h3").innerText = this.#title;
|
||||
clone.querySelector("p").innerText = this.#description;
|
||||
clone.querySelector("span").innerText = this.#upvotes;
|
||||
if (!votable) {
|
||||
let votedButton = clone.querySelector(isUpVoted? ".upvote-btn":".downvote-btn");
|
||||
|
||||
// depending on whether the button has been up/downvoted, its according button get disabled and hidden
|
||||
if (votedIDs.has(entryID)) {
|
||||
let votedButton = clone.querySelector(votedIDs.get(entryID)? ".upvote-btn":".downvote-btn");
|
||||
votedButton.classList.add("isVoted");
|
||||
votedButton.disabled = true;
|
||||
let notVotedButton = clone.querySelector(isUpVoted? ".downvote-btn":".upvote-btn");
|
||||
let notVotedButton = clone.querySelector(votedIDs.get(entryID)? ".downvote-btn":".upvote-btn");
|
||||
notVotedButton.style.visibility = "hidden";
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ for (const downvoteButton of downvoteButtons) {
|
||||
|
||||
// functions of the main page
|
||||
function navigateToAdd() {
|
||||
window.location.href = "/add";
|
||||
window.location.href = "/add"; //TODO: move to EventListner?
|
||||
}
|
||||
|
||||
function getFilterQuery() {
|
||||
@ -154,7 +154,6 @@ export function vote(entryID, up) {
|
||||
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);
|
||||
});
|
||||
|
||||
@ -202,8 +201,8 @@ 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());
|
||||
document.querySelector("#recents .datasets")
|
||||
.appendChild(dataset.createDatasetHTMLElement(dataset.getID()));
|
||||
}
|
||||
});
|
||||
|
||||
@ -215,8 +214,8 @@ function fetchInitialEntries() {
|
||||
.then(resp => resp.json())
|
||||
.then((data) => {
|
||||
let dataset = new Dataset(data.content[0]);
|
||||
//dataSets.add(dataset);
|
||||
document.querySelector("#top .datasets").appendChild(dataset.createDatasetHTMLElement());
|
||||
document.querySelector("#top .datasets")
|
||||
.appendChild(dataset.createDatasetHTMLElement(dataset.getID()));
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user