diff --git a/src/action/fetchKomik.ts b/src/action/fetchKomik.ts index 69b82bc..6a4c2e5 100644 --- a/src/action/fetchKomik.ts +++ b/src/action/fetchKomik.ts @@ -15,16 +15,11 @@ export const fetchLastUpdated = async (page: number) => { throw new Error("Error"); }; -export const fetchMangaByAdvSearch = async ( - type: string, - page: number, - title: string -) => { +export const fetchMangaByAdvSearch = async (type: string, page: number) => { const response = await axios.get( `${NEXT_MANGAZUNA_APIURL}/api/v1/manga/advsearch`, { params: { - title: title, page: page || 1, type: type, }, @@ -36,6 +31,21 @@ export const fetchMangaByAdvSearch = async ( } throw new Error("Error"); }; +export const fetchMangaAdvSearch = async (title: string) => { + const response = await axios.get( + `${NEXT_MANGAZUNA_APIURL}/api/v1/manga/advsearch`, + { + params: { + title: title, + }, + } + ); + const data = await response.data; + if (data?.status === "success") { + return data; + } + throw new Error("Error"); +}; export const fetchDetail = async (id: string) => { const response = await fetch(`${NEXT_MANGAZUNA_APIURL}/api/v1/manga/${id}`, { diff --git a/src/app/(pages)/search/page.tsx b/src/app/(pages)/search/page.tsx index 9989e2a..ef8e656 100644 --- a/src/app/(pages)/search/page.tsx +++ b/src/app/(pages)/search/page.tsx @@ -1,5 +1,5 @@ import BreadcumbPath from "@/components/ui/BreadcumbPath"; -import { fetchMangaByAdvSearch, fetchSearch } from "@/action/fetchKomik"; +import { fetchMangaAdvSearch } from "@/action/fetchKomik"; import Navbar from "@/components/Navbar"; import Image from "next/image"; import Link from "next/link"; @@ -18,7 +18,7 @@ export async function generateMetadata({ searchParams: any; }) { const query = searchParams?.q; - const getData = await fetchMangaByAdvSearch("", 1, query); + const getData = await fetchMangaAdvSearch(query); const ogImage = await getData?.data?.slice(0, 1).map((img: any) => { return img.banner ? img.banner : siteMetadata.socialBanner; }); @@ -58,7 +58,7 @@ const variant = { const page = async ({ searchParams }: { searchParams: any }) => { const query = searchParams?.q; - const getData = await fetchMangaByAdvSearch("", 1, query); + const getData = await fetchMangaAdvSearch(query); return ( <>