fixed bug
This commit is contained in:
@@ -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)
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user