diff --git a/src/main/resources/static/main.js b/src/main/resources/static/main.js index cf8b852..be8bdc6 100644 --- a/src/main/resources/static/main.js +++ b/src/main/resources/static/main.js @@ -78,13 +78,19 @@ function navigateToAdd() { function filter(filterString) { 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 fetchQuery(fetchURL); } 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 fetchQuery(fetchURL); } @@ -96,14 +102,22 @@ function sort(sortString) { } else { 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 fetchQuery(fetchURL); } function vote(entryID, up) { - console.log(apiEndpoint + "/id/" + entryID + "/" + (up ? "upvote" : "downvote")); // TODO: remove - fetch(apiEndpoint + "/id/" + entryID + "/" + (up ? "upvote" : "downvote")); + const fetchURL = new URL( + `${apiEndpoint}/id/${entryID}/${up ? "up" : "down"}vote` + ); + + console.log(fetchURL); // TODO: remove + fetch(fetchURL); } function incrementPageCount() {