diff --git a/src/main/resources/static/main.js b/src/main/resources/static/main.js index cb3f480..c7ab0aa 100644 --- a/src/main/resources/static/main.js +++ b/src/main/resources/static/main.js @@ -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() - } \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 15c2664..d345799 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -4,8 +4,8 @@