Little fixes
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
			
		||||
import { fetchQuery } from "./contentUtility.js";
 | 
			
		||||
 | 
			
		||||
const baseURL = "http://" + window.location.host + "/api/v1/datasets";
 | 
			
		||||
const apiEndpoint = "/api/v1/datasets";
 | 
			
		||||
const defaultPagingValue = 20;
 | 
			
		||||
const lastQuery = {
 | 
			
		||||
    url: "",
 | 
			
		||||
@@ -10,24 +10,31 @@ const lastQuery = {
 | 
			
		||||
 | 
			
		||||
// definition of all buttons
 | 
			
		||||
const addButton = document.getElementById("add-btn");
 | 
			
		||||
const filterButton = document.getElementById("filter-btn");
 | 
			
		||||
const searchButton = document.getElementById("search-btn");
 | 
			
		||||
const searchBar = document.getElementById("search-entry");
 | 
			
		||||
const sortButton = document.getElementById("sort-btn");
 | 
			
		||||
const upvoteButtons = document.getElementsByClassName("upvote-btn");
 | 
			
		||||
const downvoteButtons = document.getElementsByClassName("downvote-btn");
 | 
			
		||||
 | 
			
		||||
// ID of the timeout, because we need to cancel it at some point
 | 
			
		||||
export let searchBarTimeout;
 | 
			
		||||
 | 
			
		||||
// Event listeners
 | 
			
		||||
addButton.addEventListener("click", () => {
 | 
			
		||||
    navigateToAdd();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const filterButton = document.getElementById("filter-btn");
 | 
			
		||||
filterButton.addEventListener("change", () => {
 | 
			
		||||
    const filterString = filterButton.value;
 | 
			
		||||
    filter(filterString);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const searchButton = document.getElementById("search-btn");
 | 
			
		||||
searchButton.addEventListener("click", () => {
 | 
			
		||||
    const searchString = searchBar.value;
 | 
			
		||||
    search(searchString);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const searchBar = document.getElementById("search-entry");
 | 
			
		||||
export let searchBarTimeout;
 | 
			
		||||
searchBar.addEventListener("input", () => {
 | 
			
		||||
    clearTimeout(searchBarTimeout);
 | 
			
		||||
    searchBarTimeout = setTimeout(() => {
 | 
			
		||||
@@ -35,6 +42,7 @@ searchBar.addEventListener("input", () => {
 | 
			
		||||
        search(searchString);
 | 
			
		||||
    }, 1000);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
searchBar.addEventListener('keypress', function (e) {
 | 
			
		||||
    if (e.key === 'Enter') {
 | 
			
		||||
        const searchString = searchBar.value;
 | 
			
		||||
@@ -42,13 +50,11 @@ searchBar.addEventListener('keypress', function (e) {
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
const sortButton = document.getElementById("sort-btn");
 | 
			
		||||
sortButton.addEventListener("change", () => {
 | 
			
		||||
    const sortString = sortButton.value;
 | 
			
		||||
    sort(sortString);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const upvoteButtons = document.getElementsByClassName("upvote-btn");
 | 
			
		||||
const upvoteButtonClickListener = e  => {
 | 
			
		||||
    const entryID = e.target.parentElement.parentElement.dataset.id;
 | 
			
		||||
    vote(entryID, true);
 | 
			
		||||
@@ -57,7 +63,6 @@ for (const upvoteButton of upvoteButtons) {
 | 
			
		||||
    upvoteButton.addEventListener("click", upvoteButtonClickListener);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const downvoteButtons = document.getElementsByClassName("downvote-btn");
 | 
			
		||||
const downvoteButtonClickListener = e  => {
 | 
			
		||||
    const entryID = e.target.parentElement.parentElement.dataset.id;
 | 
			
		||||
    vote(entryID, false);
 | 
			
		||||
@@ -91,20 +96,16 @@ function sort(sortString) {
 | 
			
		||||
    } else {
 | 
			
		||||
        query[1] = "desc";
 | 
			
		||||
    }
 | 
			
		||||
    const fetchURL = baseURL + "?sort=" + query[0] + "&direction=" + query[1];
 | 
			
		||||
    const fetchURL = apiEndpoint + "?sort=" + query[0] + "&direction=" + query[1];
 | 
			
		||||
    console.log(fetchURL); // TODO: remove
 | 
			
		||||
    fetchQuery(fetchURL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function vote(entryID, up) {
 | 
			
		||||
    console.log(baseURL + "/id/" + entryID + "/" + (up?"upvote":"downvote")); // TODO: remove
 | 
			
		||||
    fetch(baseURL + "/id/" + entryID + "/" + up?"upvote":"downvote");
 | 
			
		||||
    console.log(apiEndpoint + "/id/" + entryID + "/" + (up ? "upvote" : "downvote")); // TODO: remove
 | 
			
		||||
    fetch(apiEndpoint + "/id/" + entryID + "/" + (up ? "upvote" : "downvote"));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function incrementPageCount() {
 | 
			
		||||
    lastQuery.currentPage++;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user