Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyIndraEfendi committed Jul 19, 2024
1 parent dfbf2fd commit 24b41da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
22 changes: 16 additions & 6 deletions src/action/fetchKomik.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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}`, {
Expand Down
6 changes: 3 additions & 3 deletions src/app/(pages)/search/page.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
});
Expand Down Expand Up @@ -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 (
<>
<Navbar />
Expand Down

0 comments on commit 24b41da

Please sign in to comment.