From 1fcdd9f7d859b925bf92265f441655d5522e351c Mon Sep 17 00:00:00 2001 From: Factiven Date: Tue, 11 Apr 2023 23:23:29 +0700 Subject: initial commit --- components/hero/trending.js | 120 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 components/hero/trending.js (limited to 'components/hero/trending.js') 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

; + if (error) return

Error :(

; + + 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 ( +
+ +
+ {media.map((anime) => { + const url = encodeURIComponent( + anime.title.english || anime.title.romaji + ); + + return ( +
+ + {anime.title.romaji + } + 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]" + /> + +
+ ); + })} +
+ +
+ ); +}; + +export default Trending; -- cgit v1.2.3