From 02d2f90e85141893fc75c43d65e56ab6c97aa1ea Mon Sep 17 00:00:00 2001 From: J-Klinke Date: Wed, 3 Jul 2024 11:52:29 +0200 Subject: [PATCH] fixed bug --- src/main/resources/static/contentUtility.js | 2 +- src/main/resources/static/main.js | 24 ++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/resources/static/contentUtility.js b/src/main/resources/static/contentUtility.js index 6030686..d08c0be 100644 --- a/src/main/resources/static/contentUtility.js +++ b/src/main/resources/static/contentUtility.js @@ -1,6 +1,6 @@ import {searchBarTimeout, searchSection, lastQuery} from "./main.js" import Dataset from "./dataset.js" - +// TODO consider renaming this to "searchUtility.js" export function fetchQuery(fetchString, clearResults) { clearTimeout(searchBarTimeout); fetch(fetchString) diff --git a/src/main/resources/static/main.js b/src/main/resources/static/main.js index 8edc846..78eaa29 100644 --- a/src/main/resources/static/main.js +++ b/src/main/resources/static/main.js @@ -69,7 +69,7 @@ resetButton.addEventListener("click", () => { updateSections(); }); -// Consider moving this to datasets.js completely +// Consider moving this to datasets.js completely // TODO: we dont need them, do we? there in dataset.js const upvoteButtonClickListener = e => { const entryID = e.target.parentElement.parentElement.dataset.id; vote(entryID, true); @@ -78,7 +78,7 @@ for (const upvoteButton of upvoteButtons) { upvoteButton.addEventListener("click", upvoteButtonClickListener); } -// Consider moving this to datasets.js completely +// Consider moving this to datasets.js completely // TODO: we dont need them, do we? there in dataset.js const downvoteButtonClickListener = e => { const entryID = e.target.parentElement.parentElement.dataset.id; vote(entryID, false); @@ -146,17 +146,17 @@ 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 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"; - votedIDs.set(dataSet.getAttribute("data-id"), up); + let dataSets = document.querySelectorAll('[data-id= ' + CSS.escape(entryID) + ']'); + for (const dataSetElement of dataSets) { + dataSetElement.querySelector("span").innerText = data.upvotes; + let votedButton = dataSetElement.querySelector(up? ".upvote-btn":".downvote-btn"); + votedButton.classList.add("isVoted"); + votedButton.disabled = true; + let notVotedButton = dataSetElement.querySelector(up? ".downvote-btn":".upvote-btn"); + notVotedButton.style.visibility = "hidden"; + votedIDs.set(dataSetElement.getAttribute("data-id"), up); + } }); - } // updates the page display. If no query is present, the initial page is shown, otherwise the search results.