fixed bug

This commit is contained in:
J-Klinke
2024-07-03 11:52:29 +02:00
parent 6d34b8c388
commit 02d2f90e85
2 changed files with 13 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
import {searchBarTimeout, searchSection, lastQuery} from "./main.js" import {searchBarTimeout, searchSection, lastQuery} from "./main.js"
import Dataset from "./dataset.js" import Dataset from "./dataset.js"
// TODO consider renaming this to "searchUtility.js"
export function fetchQuery(fetchString, clearResults) { export function fetchQuery(fetchString, clearResults) {
clearTimeout(searchBarTimeout); clearTimeout(searchBarTimeout);
fetch(fetchString) fetch(fetchString)

View File

@@ -69,7 +69,7 @@ resetButton.addEventListener("click", () => {
updateSections(); 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 upvoteButtonClickListener = e => {
const entryID = e.target.parentElement.parentElement.dataset.id; const entryID = e.target.parentElement.parentElement.dataset.id;
vote(entryID, true); vote(entryID, true);
@@ -78,7 +78,7 @@ for (const upvoteButton of upvoteButtons) {
upvoteButton.addEventListener("click", upvoteButtonClickListener); 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 downvoteButtonClickListener = e => {
const entryID = e.target.parentElement.parentElement.dataset.id; const entryID = e.target.parentElement.parentElement.dataset.id;
vote(entryID, false); vote(entryID, false);
@@ -146,17 +146,17 @@ export function vote(entryID, up) {
.then(resp => resp.json()) .then(resp => resp.json())
.then((data) => { .then((data) => {
console.log(data.upvotes); // TODO: remove, check einbauen: data.id === entryID? console.log(data.upvotes); // TODO: remove, check einbauen: data.id === entryID?
let dataSet = document.querySelector('[data-id= ' + CSS.escape(entryID) + ']') let dataSets = document.querySelectorAll('[data-id= ' + CSS.escape(entryID) + ']');
dataSet.querySelector("span").innerText = data.upvotes; for (const dataSetElement of dataSets) {
dataSetElement.querySelector("span").innerText = data.upvotes;
let votedButton = dataSet.querySelector(up? ".upvote-btn":".downvote-btn"); let votedButton = dataSetElement.querySelector(up? ".upvote-btn":".downvote-btn");
votedButton.classList.add("isVoted"); votedButton.classList.add("isVoted");
votedButton.disabled = true; votedButton.disabled = true;
let notVotedButton = dataSet.querySelector(up? ".downvote-btn":".upvote-btn"); let notVotedButton = dataSetElement.querySelector(up? ".downvote-btn":".upvote-btn");
notVotedButton.style.visibility = "hidden"; notVotedButton.style.visibility = "hidden";
votedIDs.set(dataSet.getAttribute("data-id"), up); 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. // updates the page display. If no query is present, the initial page is shown, otherwise the search results.