upvoting suppression by local storage now works, there is a bug however with the entries loaded o startup

This commit is contained in:
J-Klinke
2024-07-03 11:27:49 +02:00
parent 20eda5931a
commit 6d34b8c388
3 changed files with 16 additions and 18 deletions

View File

@@ -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";
}