From 50a0f0240d7fef133eb5acc1bea2b1168b08e9db Mon Sep 17 00:00:00 2001 From: Factiven Date: Sun, 24 Dec 2023 13:03:54 +0700 Subject: migrate to typescript --- components/watch/primary/details.tsx | 234 +++++++++++++++++++++++++++++++++++ 1 file changed, 234 insertions(+) create mode 100644 components/watch/primary/details.tsx (limited to 'components/watch/primary/details.tsx') diff --git a/components/watch/primary/details.tsx b/components/watch/primary/details.tsx new file mode 100644 index 0000000..f20f8cf --- /dev/null +++ b/components/watch/primary/details.tsx @@ -0,0 +1,234 @@ +import { useEffect, useState } from "react"; +import { useAniList } from "../../../lib/anilist/useAnilist"; +import Skeleton from "react-loading-skeleton"; +import DisqusComments from "../../disqus"; +import { AniListInfoTypes } from "types/info/AnilistInfoTypes"; +import { SessionTypes } from "pages/en"; + +type DetailsProps = { + info: AniListInfoTypes; + session: SessionTypes; + epiNumber: number; + description: string; + id: string; + onList: boolean; + setOnList: (value: boolean) => void; + handleOpen: () => void; + disqus: string; +}; + +export default function Details({ + info, + session, + epiNumber, + description, + id, + onList, + setOnList, + handleOpen, + disqus, +}: DetailsProps) { + const [showComments, setShowComments] = useState(false); + const { markPlanning } = useAniList(session); + + const [showDesc, setShowDesc] = useState(false); + + const truncatedDesc = truncateText(description, 420); + + function handlePlan() { + if (onList === false) { + markPlanning(info.id); + setOnList(true); + } + } + + useEffect(() => { + const isMobile = window.matchMedia("(max-width: 768px)").matches; + if (isMobile) { + setShowComments(false); + } else { + setShowComments(true); + } + return () => { + setShowComments(false); + setShowDesc(false); + }; + }, [id]); + + return ( +
+ {/*
*/} +
+
+ {info ? ( + Anime Cover + ) : ( + + )} +
+
+
+

+ Studios +

+
+ {info ? ( + info.studios?.edges[0].node.name + ) : ( + + )} +
+
+
+ { + session ? handlePlan() : handleOpen(); + }} + className={`w-8 h-8 hover:fill-white text-white hover:cursor-pointer ${ + onList ? "fill-white" : "" + }`} + > + + +
+
+
+
+

+ Status +

+
{info ? info.status : }
+
+
+

+ Titles +

+
+ {info ? ( + <> +
+ {info.title?.romaji || ""} +
+
+ {info.title?.english || ""} +
+
+ {info.title?.native || ""} +
+ + ) : ( + + )} +
+
+
+
+ {/*
*/} +
+ {info && + info.genres?.map((item, index) => ( +
+ {item} +
+ ))} +
+ {/*
*/} +
+ {info && ( + <> +

420 + ? truncatedDesc + : description, + }} + className={`p-5 text-sm font-light font-roboto text-[#e4e4e4] `} + /> + {!showDesc && description?.length > 120 && ( + setShowDesc((prev) => !prev)} + className="flex justify-center items-end rounded-md pb-5 font-semibold font-karla cursor-pointer w-full h-full bg-gradient-to-t from-secondary hover:from-20% to-transparent absolute inset-0" + > + Read More + + )} + + )} +

+ {/* {
} */} + {!showComments && ( +
+ +
+ )} + {showComments && ( +
+ {info && ( +
+ +
+ )} +
+ )} +
+ ); +} + +function truncateText(txt: string, length: number) { + const text = txt.replace(/(<([^>]+)>)/gi, ""); + return text.length > length ? text.slice(0, length) + "..." : text; +} -- cgit v1.2.3