Little fixes
This commit is contained in:
parent
85213b25da
commit
c19459ad01
@ -1,4 +1,4 @@
|
|||||||
import {searchBarTimeout} from "./main.js"
|
import { searchBarTimeout } from "./main.js"
|
||||||
|
|
||||||
export function fetchQuery(fetchString) {
|
export function fetchQuery(fetchString) {
|
||||||
clearTimeout(searchBarTimeout);
|
clearTimeout(searchBarTimeout);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { fetchQuery } from "./contentUtility.js";
|
import { fetchQuery } from "./contentUtility.js";
|
||||||
|
|
||||||
const baseURL = "http://" + window.location.host + "/api/v1/datasets";
|
const apiEndpoint = "/api/v1/datasets";
|
||||||
const defaultPagingValue = 20;
|
const defaultPagingValue = 20;
|
||||||
const lastQuery = {
|
const lastQuery = {
|
||||||
url: "",
|
url: "",
|
||||||
@ -10,24 +10,31 @@ const lastQuery = {
|
|||||||
|
|
||||||
// definition of all buttons
|
// definition of all buttons
|
||||||
const addButton = document.getElementById("add-btn");
|
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", () => {
|
addButton.addEventListener("click", () => {
|
||||||
navigateToAdd();
|
navigateToAdd();
|
||||||
});
|
});
|
||||||
|
|
||||||
const filterButton = document.getElementById("filter-btn");
|
|
||||||
filterButton.addEventListener("change", () => {
|
filterButton.addEventListener("change", () => {
|
||||||
const filterString = filterButton.value;
|
const filterString = filterButton.value;
|
||||||
filter(filterString);
|
filter(filterString);
|
||||||
});
|
});
|
||||||
|
|
||||||
const searchButton = document.getElementById("search-btn");
|
|
||||||
searchButton.addEventListener("click", () => {
|
searchButton.addEventListener("click", () => {
|
||||||
const searchString = searchBar.value;
|
const searchString = searchBar.value;
|
||||||
search(searchString);
|
search(searchString);
|
||||||
});
|
});
|
||||||
|
|
||||||
const searchBar = document.getElementById("search-entry");
|
|
||||||
export let searchBarTimeout;
|
|
||||||
searchBar.addEventListener("input", () => {
|
searchBar.addEventListener("input", () => {
|
||||||
clearTimeout(searchBarTimeout);
|
clearTimeout(searchBarTimeout);
|
||||||
searchBarTimeout = setTimeout(() => {
|
searchBarTimeout = setTimeout(() => {
|
||||||
@ -35,6 +42,7 @@ searchBar.addEventListener("input", () => {
|
|||||||
search(searchString);
|
search(searchString);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
searchBar.addEventListener('keypress', function (e) {
|
searchBar.addEventListener('keypress', function (e) {
|
||||||
if (e.key === 'Enter') {
|
if (e.key === 'Enter') {
|
||||||
const searchString = searchBar.value;
|
const searchString = searchBar.value;
|
||||||
@ -42,13 +50,11 @@ searchBar.addEventListener('keypress', function (e) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const sortButton = document.getElementById("sort-btn");
|
|
||||||
sortButton.addEventListener("change", () => {
|
sortButton.addEventListener("change", () => {
|
||||||
const sortString = sortButton.value;
|
const sortString = sortButton.value;
|
||||||
sort(sortString);
|
sort(sortString);
|
||||||
});
|
});
|
||||||
|
|
||||||
const upvoteButtons = document.getElementsByClassName("upvote-btn");
|
|
||||||
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);
|
||||||
@ -57,7 +63,6 @@ for (const upvoteButton of upvoteButtons) {
|
|||||||
upvoteButton.addEventListener("click", upvoteButtonClickListener);
|
upvoteButton.addEventListener("click", upvoteButtonClickListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
const downvoteButtons = document.getElementsByClassName("downvote-btn");
|
|
||||||
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);
|
||||||
@ -91,20 +96,16 @@ function sort(sortString) {
|
|||||||
} else {
|
} else {
|
||||||
query[1] = "desc";
|
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
|
console.log(fetchURL); // TODO: remove
|
||||||
fetchQuery(fetchURL);
|
fetchQuery(fetchURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
function vote(entryID, up) {
|
function vote(entryID, up) {
|
||||||
console.log(baseURL + "/id/" + entryID + "/" + (up?"upvote":"downvote")); // TODO: remove
|
console.log(apiEndpoint + "/id/" + entryID + "/" + (up ? "upvote" : "downvote")); // TODO: remove
|
||||||
fetch(baseURL + "/id/" + entryID + "/" + up?"upvote":"downvote");
|
fetch(apiEndpoint + "/id/" + entryID + "/" + (up ? "upvote" : "downvote"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function incrementPageCount() {
|
function incrementPageCount() {
|
||||||
lastQuery.currentPage++;
|
lastQuery.currentPage++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user