frontend: search fix

This commit is contained in:
Kentai Radiquum 2024-04-21 07:11:44 +05:00
parent e3a79c6864
commit dcce13b86b
Signed by: Radiquum
GPG key ID: 858E8EE696525EED

View file

@ -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