aboutsummaryrefslogtreecommitdiff
path: root/components/hero/content.js
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-04-13 16:03:57 +0700
committerFactiven <[email protected]>2023-04-13 16:03:57 +0700
commitb365d89a11adf40d37b78292f121b890e960d0e8 (patch)
tree6bd745c773dc48a2e5e4c18d2f71d54d82d682fd /components/hero/content.js
parentupdate 1 (diff)
downloadmoopa-b365d89a11adf40d37b78292f121b890e960d0e8.tar.xz
moopa-b365d89a11adf40d37b78292f121b890e960d0e8.zip
update 2nd
Diffstat (limited to 'components/hero/content.js')
-rw-r--r--components/hero/content.js119
1 files changed, 66 insertions, 53 deletions
diff --git a/components/hero/content.js b/components/hero/content.js
index 532e4a6..a3db854 100644
--- a/components/hero/content.js
+++ b/components/hero/content.js
@@ -1,9 +1,12 @@
import Link from "next/link";
-import React from "react";
+import React, { useState } from "react";
import Image from "next/image";
import { MdChevronLeft, MdChevronRight } from "react-icons/md";
export default function Content({ ids, section, data }) {
+ const [scrollLeft, setScrollLeft] = useState(false);
+ const [scrollRight, setScrollRight] = useState(true);
+
const slideLeft = () => {
var slider = document.getElementById(ids);
slider.scrollLeft = slider.scrollLeft - 500;
@@ -13,65 +16,75 @@ export default function Content({ ids, section, data }) {
slider.scrollLeft = slider.scrollLeft + 500;
};
+ const handleScroll = (e) => {
+ const scrollLeft = e.target.scrollLeft > 31;
+ const scrollRight =
+ e.target.scrollLeft < e.target.scrollWidth - e.target.clientWidth;
+ setScrollLeft(scrollLeft);
+ setScrollRight(scrollRight);
+ };
+
+ // console.log({ left: scrollLeft, right: scrollRight });
+
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"
+ <h1 className="px-5 font-karla text-[20px] font-bold">{section}</h1>
+ <div className="relative flex items-center lg:gap-2">
+ <MdChevronLeft
+ onClick={slideLeft}
+ size={35}
+ className={`mb-5 cursor-pointer absolute left-0 bg-gradient-to-r from-[#141519] z-40 h-full hover:opacity-100 ${
+ scrollLeft ? "visible" : "hidden"
+ }`}
+ />
+ <div
+ id={ids}
+ className="scroll flex h-full w-full items-center select-none overflow-x-scroll scroll-smooth whitespace-nowrap overflow-y-hidden scrollbar-hide lg:gap-8 gap-5 p-10 z-30 "
+ onScroll={handleScroll}
+ >
+ {filteredData.map((anime) => {
+ return (
+ <div
+ key={anime.id}
+ className="flex shrink-0 cursor-pointer items-center"
+ >
+ <Link
+ href={`/anime/${anime.id}`}
+ className="hover:scale-105 duration-300 ease-in-out"
>
- <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"
- />
+ <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-[192px] w-[135px] object-cover lg:h-[265px] lg:w-[185px] rounded-md"
+ />
+ </Link>
+ </div>
+ );
+ })}
</div>
+ <MdChevronRight
+ onClick={slideRight}
+ size={30}
+ className={`mb-5 cursor-pointer absolute right-0 bg-gradient-to-l from-[#141519] z-40 h-full hover:opacity-100 hover:bg-gradient-to-l ${
+ scrollRight ? "visible" : "hidden"
+ }`}
+ />
</div>
</div>
);