Skip to content
Snippets Groups Projects
Commit 296d7172 authored by Trirst's avatar Trirst
Browse files

Helper function for parsing query value

parent 2face179
Branches
No related tags found
No related merge requests found
<script> <script>
import { onMount } from "svelte"; import { onMount } from "svelte";
import { paths } from "@/static/js/paths"; import { paths } from "@/static/js/paths";
import { fetchAPI } from "@/static/js/helper"; import { fetchAPI, getQueryValue } from "@/static/js/helper";
import ImageList from "@/lib/ImageList.svelte"; import ImageList from "@/lib/ImageList.svelte";
import PaginationBar from "@/lib/PaginationBar.svelte"; import PaginationBar from "@/lib/PaginationBar.svelte";
import { querystring } from "svelte-spa-router"; import { querystring } from "svelte-spa-router";
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
let currentPage; let currentPage;
let lastPage; let lastPage;
$: if ($querystring !== "") $: if ($querystring !== "")
currentPage = parseInt(new URLSearchParams($querystring).get("p")); currentPage = parseInt(getQueryValue($querystring, "p"));
$: getPageSnowflakes(currentPage - 1).then( $: getPageSnowflakes(currentPage - 1).then(
(snowflakes) => (pageSnowflakes = snowflakes || []) (snowflakes) => (pageSnowflakes = snowflakes || [])
); );
......
...@@ -9,4 +9,8 @@ async function fetchAPI(endpoint, options) { ...@@ -9,4 +9,8 @@ async function fetchAPI(endpoint, options) {
} }
} }
export { fetchAPI }; function getQueryValue(querystring, query) {
\ No newline at end of file return new URLSearchParams(querystring).get(query)
}
export { fetchAPI, getQueryValue };
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment