main.js further implemented

This commit is contained in:
J-Klinke
2024-06-18 16:38:09 +02:00
parent cddfdf546a
commit d5fd98a066
2 changed files with 19 additions and 14 deletions

View File

@@ -16,7 +16,7 @@ searchButton.addEventListener("click", () => {
search(searchString);
});
const searchBar = document.getElementById("search-entry");
searchBar.addEventListener("change", () => {
searchBar.addEventListener("input", () => {
const searchString = searchBar.value;
search(searchString);
});
@@ -27,17 +27,23 @@ sortButton.addEventListener("change", () => {
sort(sortString);
});
const upvoteButton = document.getElementsByClassName("upvote-btn");
upvoteButton.addEventListener("click", () => {
//const entryID = ;
const upvoteButtons = document.getElementsByClassName("upvote-btn");
const upvoteButtonClickListener = () => {
const entryID = upvoteButton.parent.dataset.id;
vote(entryID, true);
});
};
for (const upvoteButton of upvoteButtons) {
upvoteButton.addEventListener("click", upvoteButtonClickListener);
}
const downvoteButton = document.getElementsByClassName("downvote-btn");
downvoteButton.addEventListener("click", () => {
//const entryID;
const downvoteButtons = document.getElementsByClassName("downvote-btn");
const downvoteButtonClickListener = () => {
const entryID = downvoteButton.parent.dataset.id;
vote(entryID, false);
});
};
for (const downvoteButton of downvoteButtons) {
downvoteButton.addEventListener("click", downvoteButtonClickListener);
}
function navigateToAdd() {
@@ -48,7 +54,7 @@ function filter(filterString) {
}
function search(searchString) {
console.log(searchString);
}
function sort(sortString) {
@@ -57,5 +63,4 @@ function sort(sortString) {
function vote(entryID, up) {
fetch()
}