Fix voting event listeners in search

This commit is contained in:
Elias Schriefer
2024-06-25 09:59:39 +02:00
parent e47edf3cf2
commit a340d59ca2
2 changed files with 15 additions and 1 deletions

View File

@@ -61,6 +61,7 @@ sortButton.addEventListener("change", () => {
sort(sortString);
});
// Consider moving this to datasets.js completely
const upvoteButtonClickListener = e => {
const entryID = e.target.parentElement.parentElement.dataset.id;
vote(entryID, true);
@@ -69,6 +70,7 @@ for (const upvoteButton of upvoteButtons) {
upvoteButton.addEventListener("click", upvoteButtonClickListener);
}
// Consider moving this to datasets.js completely
const downvoteButtonClickListener = e => {
const entryID = e.target.parentElement.parentElement.dataset.id;
vote(entryID, false);
@@ -115,7 +117,7 @@ function sort(sortString) {
fetchQuery(fetchURL);
}
function vote(entryID, up) {
export function vote(entryID, up) {
const fetchURL = new URL(
`${apiEndpoint}/id/${entryID}/${up ? "up" : "down"}vote`,
baseURL,