Fix voting event listeners in search
This commit is contained in:
parent
e47edf3cf2
commit
a340d59ca2
@ -1,3 +1,5 @@
|
|||||||
|
import { vote } from "./main.js";
|
||||||
|
|
||||||
export default class Dataset {
|
export default class Dataset {
|
||||||
#abstract;
|
#abstract;
|
||||||
#author;
|
#author;
|
||||||
@ -34,6 +36,16 @@ export default class Dataset {
|
|||||||
clone.querySelector("h3").innerText = this.#title;
|
clone.querySelector("h3").innerText = this.#title;
|
||||||
clone.querySelector("p").innerText = this.#description;
|
clone.querySelector("p").innerText = this.#description;
|
||||||
clone.querySelector("span").innerText = this.#upvotes;
|
clone.querySelector("span").innerText = this.#upvotes;
|
||||||
|
|
||||||
|
// Event Listeners
|
||||||
|
clone.querySelector(".upvote-btn").addEventListener("click", () => {
|
||||||
|
vote(this.#id, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
clone.querySelector(".downvote-btn").addEventListener("click", () => {
|
||||||
|
vote(this.#id, false);
|
||||||
|
})
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ sortButton.addEventListener("change", () => {
|
|||||||
sort(sortString);
|
sort(sortString);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Consider moving this to datasets.js completely
|
||||||
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);
|
||||||
@ -69,6 +70,7 @@ for (const upvoteButton of upvoteButtons) {
|
|||||||
upvoteButton.addEventListener("click", upvoteButtonClickListener);
|
upvoteButton.addEventListener("click", upvoteButtonClickListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Consider moving this to datasets.js completely
|
||||||
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);
|
||||||
@ -115,7 +117,7 @@ function sort(sortString) {
|
|||||||
fetchQuery(fetchURL);
|
fetchQuery(fetchURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
function vote(entryID, up) {
|
export function vote(entryID, up) {
|
||||||
const fetchURL = new URL(
|
const fetchURL = new URL(
|
||||||
`${apiEndpoint}/id/${entryID}/${up ? "up" : "down"}vote`,
|
`${apiEndpoint}/id/${entryID}/${up ? "up" : "down"}vote`,
|
||||||
baseURL,
|
baseURL,
|
||||||
|
Loading…
Reference in New Issue
Block a user