Rework URL construction

This commit is contained in:
Elias Schriefer 2024-06-21 12:17:16 +02:00
parent 5fda42856d
commit 5168ccaf62

View File

@ -78,13 +78,19 @@ function navigateToAdd() {
function filter(filterString) { function filter(filterString) {
filterString = filterString.toUpperCase(); filterString = filterString.toUpperCase();
const fetchURL = apiEndpoint + "?type=" + encodeURIComponent(filterString) + "&size=" + defaultPagingValue;
let fetchURL = new URL(apiEndpoint);
fetchURL.searchParams.append("type", filterString);
fetchURL.searchParams.append("size", defaultPagingValue);
console.log(fetchURL); // TODO: remove console.log(fetchURL); // TODO: remove
fetchQuery(fetchURL); fetchQuery(fetchURL);
} }
function search(searchString) { function search(searchString) {
const fetchURL = apiEndpoint + "/search" + "?search=" + encodeURIComponent(searchString.length === 0?"%":searchString); let fetchURL = new URL(apiEndpoint + "/search");
fetchURL.searchParams.append("search", searchString.length == 0 ? "%" : searchString);
console.log(fetchURL); // TODO: remove console.log(fetchURL); // TODO: remove
fetchQuery(fetchURL); fetchQuery(fetchURL);
} }
@ -96,14 +102,22 @@ function sort(sortString) {
} else { } else {
query[1] = "desc"; query[1] = "desc";
} }
const fetchURL = apiEndpoint + "?sort=" + query[0] + "&direction=" + query[1];
let fetchURL = new URL(apiEndpoint);
fetchURL.searchParams.append("sort", query[0]);
fetchURL.searchParams.append("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(apiEndpoint + "/id/" + entryID + "/" + (up ? "upvote" : "downvote")); // TODO: remove const fetchURL = new URL(
fetch(apiEndpoint + "/id/" + entryID + "/" + (up ? "upvote" : "downvote")); `${apiEndpoint}/id/${entryID}/${up ? "up" : "down"}vote`
);
console.log(fetchURL); // TODO: remove
fetch(fetchURL);
} }
function incrementPageCount() { function incrementPageCount() {