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()
}

View File

@ -4,8 +4,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DataDash</title>
<link rel="stylesheet" href="../static/main.css">
<script type="text/javascript" src="../static/main.js"></script>
<link rel="stylesheet" href="main.css">
<script type="text/javascript" src="main.js" defer></script>
</head>
<body>
<div onclick="console.log('add')" id="add-btn" title="Add a new API entry"></div>
@ -38,7 +38,7 @@
<h2>Recently added:</h2>
<ul class="datasets">
<!-- Preliminary content to be replaced by data from our server: -->
<li class="dataset">
<li class="dataset" data-id="">
<div class="dataset-info">
<div class="icon standup"></div>
<div class="details">