From 62b0d5c028a1f8140f0904b0f94229a6c095b5d1 Mon Sep 17 00:00:00 2001 From: J-Klinke Date: Wed, 3 Jul 2024 12:08:59 +0200 Subject: [PATCH] local storage now properly implemented, (sessionstorage) --- src/main/resources/static/dataset.js | 6 +++--- src/main/resources/static/main.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/resources/static/dataset.js b/src/main/resources/static/dataset.js index b13b7b6..947770f 100644 --- a/src/main/resources/static/dataset.js +++ b/src/main/resources/static/dataset.js @@ -38,11 +38,11 @@ export default class Dataset { clone.querySelector("span").innerText = this.#upvotes; // 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"); + if (votedIDs.getItem(entryID)) { + let votedButton = clone.querySelector(votedIDs.getItem(entryID)? ".upvote-btn":".downvote-btn"); votedButton.classList.add("isVoted"); votedButton.disabled = true; - let notVotedButton = clone.querySelector(votedIDs.get(entryID)? ".downvote-btn":".upvote-btn"); + let notVotedButton = clone.querySelector(votedIDs.getItem(entryID)? ".downvote-btn":".upvote-btn"); notVotedButton.style.visibility = "hidden"; } diff --git a/src/main/resources/static/main.js b/src/main/resources/static/main.js index 78eaa29..52ee670 100644 --- a/src/main/resources/static/main.js +++ b/src/main/resources/static/main.js @@ -8,7 +8,7 @@ export const lastQuery = { totalPages: 0, currentPage: 0 }; -export const votedIDs = new Map; +export const votedIDs = window.sessionStorage; // definition of all buttons & sections const addButton = document.getElementById("add-btn"); @@ -154,7 +154,7 @@ export function vote(entryID, up) { votedButton.disabled = true; let notVotedButton = dataSetElement.querySelector(up? ".downvote-btn":".upvote-btn"); notVotedButton.style.visibility = "hidden"; - votedIDs.set(dataSetElement.getAttribute("data-id"), up); + votedIDs.setItem(dataSetElement.getAttribute("data-id"), up); } }); }