aboutsummaryrefslogtreecommitdiff
path: root/components/hero
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-04-11 23:23:29 +0700
committerFactiven <[email protected]>2023-04-11 23:23:29 +0700
commit1fcdd9f7d859b925bf92265f441655d5522e351c (patch)
tree86391522f6fcc70d105f7e796a9f91d132ee4a29 /components/hero
parentInitial commit (diff)
downloadmoopa-1fcdd9f7d859b925bf92265f441655d5522e351c.tar.xz
moopa-1fcdd9f7d859b925bf92265f441655d5522e351c.zip
initial commit
Diffstat (limited to 'components/hero')
-rw-r--r--components/hero/content.js78
-rw-r--r--components/hero/searchAni.js64
-rw-r--r--components/hero/trending.js120
3 files changed, 262 insertions, 0 deletions
diff --git a/components/hero/content.js b/components/hero/content.js
new file mode 100644
index 0000000..532e4a6
--- /dev/null
+++ b/components/hero/content.js
@@ -0,0 +1,78 @@
+import Link from "next/link";
+import React from "react";
+import Image from "next/image";
+import { MdChevronLeft, MdChevronRight } from "react-icons/md";
+
+export default function Content({ ids, section, data }) {
+ const slideLeft = () => {
+ var slider = document.getElementById(ids);
+ slider.scrollLeft = slider.scrollLeft - 500;
+ };
+ const slideRight = () => {
+ var slider = document.getElementById(ids);
+ slider.scrollLeft = slider.scrollLeft + 500;
+ };
+
+ const array = data;
+ const filteredData = array.filter((item) => item.status !== "Unknown");
+
+ return (
+ <div>
+ <h1 className="px-5 font-outfit text-[20px] font-extrabold lg:text-[27px]">
+ {section}
+ </h1>
+ <div className="py-10">
+ <div className="relative flex items-center lg:gap-2">
+ <MdChevronLeft
+ onClick={slideLeft}
+ size={40}
+ className="mb-5 cursor-pointer opacity-50 hover:opacity-100"
+ />
+ <div
+ id={ids}
+ className="scroll flex h-full w-full items-center overflow-x-scroll scroll-smooth whitespace-nowrap overflow-y-hidden scrollbar-hide lg:gap-5"
+ >
+ {filteredData.map((anime) => {
+ const url = encodeURIComponent(
+ anime.title.english || anime.title.romaji
+ );
+
+ return (
+ <div
+ key={anime.id}
+ className="flex shrink-0 cursor-pointer items-center"
+ >
+ <Link href={`/anime/${anime.id}`}>
+ <Image
+ draggable={false}
+ src={
+ anime.image ||
+ anime.coverImage?.extraLarge ||
+ "https://cdn.discordapp.com/attachments/986579286397964290/1058415946945003611/gray_pfp.png"
+ }
+ alt={anime.title.romaji || anime.title.english}
+ width={209}
+ height={300}
+ placeholder="blur"
+ blurDataURL={
+ anime.image ||
+ anime.coverImage?.extraLarge ||
+ "https://cdn.discordapp.com/attachments/986579286397964290/1058415946945003611/gray_pfp.png"
+ }
+ className="z-20 h-[230px] w-[168px] object-cover p-2 duration-300 ease-in-out hover:scale-105 lg:h-[290px] lg:w-[209px]"
+ />
+ </Link>
+ </div>
+ );
+ })}
+ </div>
+ <MdChevronRight
+ onClick={slideRight}
+ size={40}
+ className="mb-5 cursor-pointer opacity-50 hover:opacity-100"
+ />
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/components/hero/searchAni.js b/components/hero/searchAni.js
new file mode 100644
index 0000000..390165a
--- /dev/null
+++ b/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;
diff --git a/components/hero/trending.js b/components/hero/trending.js
new file mode 100644
index 0000000..24a6804
--- /dev/null
+++ b/components/hero/trending.js
@@ -0,0 +1,120 @@
+import React from "react";
+import { useQuery, gql } from "@apollo/client";
+import { MdChevronLeft, MdChevronRight } from "react-icons/md";
+import Link from "next/link";
+import Image from "next/image";
+
+const Trending = () => {
+ 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
+ }
+ description
+ bannerImage
+ type
+ popularity
+ averageScore
+ }
+ }
+ }
+ `;
+
+ // use useQuery hook to execute query and get data
+ const { loading, error, data } = useQuery(ANIME_QUERY, {
+ variables: {
+ page: 1,
+ perPage: 15,
+ sort: "TRENDING_DESC",
+ },
+ });
+
+ // render component
+ if (loading) return <p></p>;
+ if (error) return <p>Error :(</p>;
+
+ const { media } = data.Page;
+
+ const slideLeft = () => {
+ var slider = document.getElementById("slider");
+ slider.scrollLeft = slider.scrollLeft - 500;
+ };
+ const slideRight = () => {
+ var slider = document.getElementById("slider");
+ slider.scrollLeft = slider.scrollLeft + 500;
+ };
+
+ return (
+ <div className="relative flex items-center gap-0 lg:gap-2">
+ <MdChevronLeft
+ onClick={slideLeft}
+ size={40}
+ className="mb-5 cursor-pointer opacity-50 hover:opacity-100"
+ />
+ <div
+ id="slider"
+ className="scroll flex h-full w-full items-center overflow-x-scroll scroll-smooth whitespace-nowrap overflow-y-hidden scrollbar-hide lg:gap-5 "
+ >
+ {media.map((anime) => {
+ const url = encodeURIComponent(
+ anime.title.english || anime.title.romaji
+ );
+
+ return (
+ <div
+ key={anime.id}
+ className="flex shrink-0 cursor-pointer lg:items-center "
+ >
+ <Link href={`/anime/${anime.id}`}>
+ <Image
+ src={anime.coverImage.large}
+ alt={anime.title.romaji || anime.title.english}
+ width={209}
+ height={300}
+ skeleton={
+ <div
+ style={{
+ backgroundColor: "lightgray",
+ width: 209,
+ height: 300,
+ }}
+ />
+ }
+ className="z-20 h-[230px] w-[168px] object-cover p-2 duration-300 ease-in-out hover:scale-105 lg:h-[290px] lg:w-[209px]"
+ />
+ </Link>
+ </div>
+ );
+ })}
+ </div>
+ <MdChevronRight
+ onClick={slideRight}
+ size={40}
+ className="mb-5 cursor-pointer opacity-50 hover:opacity-100"
+ />
+ </div>
+ );
+};
+
+export default Trending;