aboutsummaryrefslogtreecommitdiff
path: root/pages/components/hero/searchAni.js
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-04-14 00:07:02 +0700
committerFactiven <[email protected]>2023-04-14 00:07:02 +0700
commit482b1c8db5cfeaa20d75ce92fcb10f3ca8433633 (patch)
treef0c12d3acb6bd8ce43e63e01527c97a62dba7e9c /pages/components/hero/searchAni.js
parentUpdate index.js (diff)
downloadmoopa-482b1c8db5cfeaa20d75ce92fcb10f3ca8433633.tar.xz
moopa-482b1c8db5cfeaa20d75ce92fcb10f3ca8433633.zip
Update 5th
Diffstat (limited to 'pages/components/hero/searchAni.js')
-rw-r--r--pages/components/hero/searchAni.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/pages/components/hero/searchAni.js b/pages/components/hero/searchAni.js
new file mode 100644
index 0000000..390165a
--- /dev/null
+++ b/pages/components/hero/searchAni.js
@@ -0,0 +1,64 @@
+import React from "react";
+import { useQuery, gql } from "@apollo/client";
+import Link from "next/link";
+
+const SearchAni = ({ searchQuery }) => {
+ const ANIME_QUERY = gql`
+ query (
+ $id: Int
+ $page: Int
+ $perPage: Int
+ $search: String
+ $sort: [MediaSort]
+ ) {
+ Page(page: $page, perPage: $perPage) {
+ pageInfo {
+ total
+ currentPage
+ lastPage
+ hasNextPage
+ perPage
+ }
+ media(id: $id, search: $search, sort: $sort, type: ANIME) {
+ id
+ idMal
+ title {
+ romaji
+ english
+ }
+ coverImage {
+ large
+ }
+ }
+ }
+ }
+ `;
+
+ // use useQuery hook to execute query and get data
+ const { loading, error, data } = useQuery(ANIME_QUERY, {
+ variables: {
+ search: searchQuery,
+ page: 1,
+ perPage: 5,
+ sort: "TRENDING_DESC",
+ },
+ });
+
+ // render component
+ if (loading) return <p>Loading...</p>;
+ if (error) return <p>Error :(</p>;
+
+ const { media } = data.Page;
+
+ // const cleanDescription = description.replace(/<br>/g, '').replace(/\n/g, ' ');
+
+ return (
+ <main className="flex flex-col">
+ <div className="my-10 mx-[1rem] flex flex-col gap-10 md:mx-auto md:w-full">
+ {media.map((anime) => {})}
+ </div>
+ </main>
+ );
+};
+
+export default SearchAni;