From 296d71722dd614d76ae9aa3e064893c0970ca711 Mon Sep 17 00:00:00 2001
From: Trirst <abeces968@gmail.com>
Date: Mon, 18 Oct 2021 00:46:26 +0700
Subject: [PATCH] Helper function for parsing query value

---
 src/routes/Browse.svelte | 4 ++--
 src/static/js/helper.js  | 6 +++++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/routes/Browse.svelte b/src/routes/Browse.svelte
index 0b6de17..1427fef 100644
--- a/src/routes/Browse.svelte
+++ b/src/routes/Browse.svelte
@@ -1,7 +1,7 @@
 <script>
     import { onMount } from "svelte";
     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 PaginationBar from "@/lib/PaginationBar.svelte";
     import { querystring } from "svelte-spa-router";
@@ -10,7 +10,7 @@
     let currentPage;
     let lastPage;
     $: if ($querystring !== "")
-        currentPage = parseInt(new URLSearchParams($querystring).get("p"));
+        currentPage = parseInt(getQueryValue($querystring, "p"));
     $: getPageSnowflakes(currentPage - 1).then(
         (snowflakes) => (pageSnowflakes = snowflakes || [])
     );
diff --git a/src/static/js/helper.js b/src/static/js/helper.js
index 02e9aa4..334fe45 100644
--- a/src/static/js/helper.js
+++ b/src/static/js/helper.js
@@ -9,4 +9,8 @@ async function fetchAPI(endpoint, options) {
     }
 }
 
-export { fetchAPI };
\ No newline at end of file
+function getQueryValue(querystring, query) {
+    return new URLSearchParams(querystring).get(query)
+}
+
+export { fetchAPI, getQueryValue };
\ No newline at end of file
-- 
GitLab