diff --git a/frontend/app/search/page.js b/frontend/app/search/page.js index 7ddedf5..4d42cda 100644 --- a/frontend/app/search/page.js +++ b/frontend/app/search/page.js @@ -3,7 +3,7 @@ import { getData } from "@/app/api/api-utils"; import { endpoints } from "@/app/api/config"; import { useEffect, useState, useCallback } from "react"; -import { useRouter } from "next/navigation"; +import { usePathname, useRouter } from "next/navigation"; import { CardList } from "@/app/components/CardList/CardList"; import { useSearchParams } from "next/navigation"; @@ -16,10 +16,12 @@ export function getSearches() { export default function Search() { const router = useRouter(); + const pathname = usePathname(); const [releases, setReleases] = useState(); const [page, setPage] = useState(0); const [query, setQuery] = useState(""); + const [searches, setSearches] = useState(JSON.parse(getSearches())); const searchParams = useSearchParams(); @@ -45,6 +47,14 @@ export default function Search() { } } + useEffect(() => { + const query = searchParams.get("query"); + if (query) { + setQuery(query); + fetchData(query, 0); + } + }, []); + useEffect(() => { if (releases) { fetchData(query, page); // Use fetchData for pagination