From ae41b28c9467f4802c576957be861d9395c5fd0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bj=C3=B8ralt?= Date: Thu, 19 Oct 2023 10:47:09 +0200 Subject: [PATCH] Fix dept filter --- frontend/src/components/FilterButton.tsx | 5 +++-- frontend/src/data/fetchWithToken.ts | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/FilterButton.tsx b/frontend/src/components/FilterButton.tsx index 054ba132..6fa99edc 100644 --- a/frontend/src/components/FilterButton.tsx +++ b/frontend/src/components/FilterButton.tsx @@ -1,9 +1,10 @@ "use client"; -import { useRouter, useSearchParams } from "next/navigation"; +import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useState } from "react"; export default function FilterButton({ filterName }: { filterName: string }) { const router = useRouter(); + const pathname = usePathname(); const searchParams = useSearchParams(); const [isButtonActive, setIsButtonActive] = useState(checkFilterInUrl); @@ -21,7 +22,7 @@ export default function FilterButton({ filterName }: { filterName: string }) { newFilters.splice(filterIndex, 1); } const newFilterString = newFilters.join(",").replace(/^,/, ""); - router.push(`/bemanning?search=${currentSearch}&filter=${newFilterString}`); + router.push(`${pathname}?search=${currentSearch}&filter=${newFilterString}`); } function checkFilterInUrl() { diff --git a/frontend/src/data/fetchWithToken.ts b/frontend/src/data/fetchWithToken.ts index 55fb36f6..f574410f 100644 --- a/frontend/src/data/fetchWithToken.ts +++ b/frontend/src/data/fetchWithToken.ts @@ -26,8 +26,13 @@ export async function fetchWithToken(path: string): Promise { method: "GET", headers: headers, }; - const response = await fetch(`${apiBackendUrl}/${path}`, options); - return (await response.json()) as T; + try{ + const response = await fetch(`${apiBackendUrl}/${path}`, options); + return (await response.json()) as T; + } catch (e) { + console.log(`${apiBackendUrl}/${path}`) + console.error(e) + } } function mockedCall(path: string): Promise {