diff --git a/src/components/carousel/carousel.scss b/src/components/carousel/carousel.scss index ca90520..ab59c02 100644 --- a/src/components/carousel/carousel.scss +++ b/src/components/carousel/carousel.scss @@ -1,15 +1,42 @@ .carousel { position: relative; - height: 64vh; - width: calc(100% + 2*$page-margin); - left: -$page-margin; - margin-bottom: 3.2em; - .slider { - position: absolute; - bottom: 0; - max-width: 35%; - right: $page-margin; + overflow: hidden; + height: 62vh; + margin-bottom: 2em; + display: grid; + grid-template-areas: "main sidebar"; + grid-template-columns: 1fr 25vw; + gap: 1em; + + &-sidebar { + overflow-y: auto; + height: inherit; + background: rgb(0 0 0 / 0.2); + border-radius: 20px; + border: 1.2px solid rgb(255 255 255 / 0.1); + grid-area: sidebar; + + &::-webkit-scrollbar { + width: 14px; } + + &::-webkit-scrollbar-track { + background: transparent; + margin-block: 1em; + } + + &::-webkit-scrollbar-thumb { + background-color: rgba(255, 255, 255, 0.2); + border-radius: 10px; + border: 4px solid transparent; + background-clip: content-box; + + &:hover { + background-color: rgba(255, 255, 255, 0.4); + } + } + } + &-button { position: absolute !important; top: 50%; @@ -25,14 +52,46 @@ } } + &-ticker{ + overflow: hidden; + height: 8em; + display: flex; + // margin-bottom: 1em; + padding: 1em; + align-items: center; + gap: 1em; + border-bottom: 1px solid rgb(255 255 255 / 0.1); + transition: background $transition-time-fast; + + &:last-child { + margin-bottom: 0; + border: none; + } + + &:hover { + background: rgb(0 0 0 / .25); + cursor: pointer; + } + + &.active { + background: rgb(255 255 255 / 0.05); + } + + &-image { + height: 100%; + border-radius: 4px; + object-fit: cover; + } + } + &-indicator { aspect-ratio: 1.77777; - overflow: hidden; - border-radius: 2px; - padding: 2px; - transition: opacity $transition-time-fast; - opacity: 0.5; - width: auto; + overflow: hidden; + border-radius: 2px; + padding: 2px; + transition: opacity $transition-time-fast; + opacity: 0.5; + width: auto; &:hover { cursor: pointer; opacity: 0.8; @@ -44,29 +103,29 @@ align-items: center; justify-content: center; } -&-image { - width: 100%; - height: 100%; - object-fit: cover; - border-radius: 4px; -} - -&-icon { - display: flex; - align-items: center; - justify-content: center; - width: 100%; - height: 100%; - background: rgb(155 155 155 / 0.4); - border-radius: 4px; -} + &-image { + width: 100%; + height: 100%; + object-fit: cover; + border-radius: 4px; + } + + &-icon { + display: flex; + align-items: center; + justify-content: center; + width: 100%; + height: 100%; + background: rgb(155 155 155 / 0.4); + border-radius: 4px; + } &.active { opacity: 1; - .material-symbols-rounded { - - --fill: 1; - } - } + .material-symbols-rounded { + + --fill: 1; } + } + } } \ No newline at end of file diff --git a/src/components/carousel/index.tsx b/src/components/carousel/index.tsx index e8c59df..e3f4ad6 100644 --- a/src/components/carousel/index.tsx +++ b/src/components/carousel/index.tsx @@ -1,29 +1,20 @@ -import { AnimatePresence, motion } from "motion/react"; -import type { PanInfo } from "motion/react"; -import React, { useEffect, useState, useMemo, useCallback } from "react"; -import type { MouseEvent, PointerEvent } from "react"; +import { AnimatePresence } from "motion/react"; +import React, { useCallback, useEffect, useState } from "react"; import { useCarouselStore } from "../../utils/store/carousel"; import "./carousel.scss"; -import { useApiInContext } from "@/utils/store/api"; -import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client"; -import CarouselSlide from "../carouselSlide"; - +import { + type BaseItemDto, + BaseItemKind, +} from "@jellyfin/sdk/lib/generated-client"; import getImageUrlsApi from "@/utils/methods/getImageUrlsApi"; -import Slider from "../Slider"; -import { getTypeIcon } from "../utils/iconsCollection"; - -const swipeConfidenceThreshold = 8000; -const swipePower = (offset: number, velocity: number) => { - return Math.abs(offset) * velocity; -}; +import { useApiInContext } from "@/utils/store/api"; +import CarouselSlide from "../carouselSlide"; +import CarouselTickers from "./tickers"; // Memoize CarouselSlide to prevent unnecessary re-renders const MemoizedCarouselSlide = React.memo(CarouselSlide); -// Memoize Slider to prevent unnecessary re-renders -const MemoizedSlider = React.memo(Slider); - const Carousel = ({ content, onChange, @@ -41,112 +32,50 @@ const Carousel = ({ const api = useApiInContext((s) => s.api); - // Memoize the content mapping - const sliderContent = useMemo(() => { - return content.map((item, index) => { - return ( - { - if (currentSlide > index) { - setDirection("left"); - } else if (currentSlide <= index) { - setDirection("right"); - } - setCurrentSlide(index); - }} - > - {item.ImageTags?.Thumb ? ( - {item.Name - ) : ( -
- {getTypeIcon(item.Type ?? "Movie")} -
- )} -
- ); - }); - }, [content, currentSlide, api, setDirection]); - - const handleDragEnd = useCallback( - ( - _: MouseEvent | TouchEvent | PointerEvent, - { offset, velocity }: PanInfo, - ) => { - const swipe = swipePower(offset.x, velocity.x); - if ( - currentSlide !== content.length - 1 && - swipe < -swipeConfidenceThreshold - ) { - setDirection("right"); - setCurrentSlide((init) => init + 1); - } else if (currentSlide !== 0 && swipe > swipeConfidenceThreshold) { - setDirection("left"); - setCurrentSlide((init) => init - 1); - } + const handleTickerClick = useCallback( + (index: number) => { + if (index === currentSlide) return; + setDirection(index > currentSlide ? "right" : "left"); + setCurrentSlide(index); }, - [currentSlide, content.length, setDirection], + [currentSlide, setDirection], ); + if (!api) return null; + return (
- - - + - +
+ {content.map((item, index) => ( + handleTickerClick(index)} + /> + ))} +
); }; diff --git a/src/components/carousel/tickers.tsx b/src/components/carousel/tickers.tsx new file mode 100644 index 0000000..bbd828c --- /dev/null +++ b/src/components/carousel/tickers.tsx @@ -0,0 +1,41 @@ +import { Typography } from "@mui/material"; +import React from "react"; + +type CarouselTickersProps = { + imageUrl?: string; + itemName: string; + itemYear: string; + onClick: () => void; + isActive: boolean; +}; + +const CarouselTickers = ({ + imageUrl, + itemName, + itemYear, + onClick, + isActive, +}: CarouselTickersProps) => { + return ( +
+ {itemName} +
+ + {itemName} + + + {itemYear} + +
+
+ ); +}; +export default CarouselTickers; diff --git a/src/components/carouselSlide/index.tsx b/src/components/carouselSlide/index.tsx index 4f3c1f0..b59b633 100644 --- a/src/components/carouselSlide/index.tsx +++ b/src/components/carouselSlide/index.tsx @@ -1,29 +1,47 @@ -import React from "react"; - -import { motion } from "motion/react"; - -import Button from "@mui/material/Button"; -import Chip from "@mui/material/Chip"; -import Stack from "@mui/material/Stack"; -import Typography from "@mui/material/Typography"; - -import { yellow } from "@mui/material/colors"; - -import { endsAt, getRuntime } from "@/utils/date/time"; -import { green, red } from "@mui/material/colors"; -import { useNavigate } from "@tanstack/react-router"; -import { getTypeIcon } from "../utils/iconsCollection"; - -import { useApiInContext } from "@/utils/store/api"; -import { useCarouselStore } from "@/utils/store/carousel"; -import { useCentralStore } from "@/utils/store/central"; import { type BaseItemDto, BaseItemKind, } from "@jellyfin/sdk/lib/generated-client"; +import Button from "@mui/material/Button"; +import Chip from "@mui/material/Chip"; +import { green, red, yellow } from "@mui/material/colors"; +import Stack from "@mui/material/Stack"; +import Typography from "@mui/material/Typography"; +import { useNavigate } from "@tanstack/react-router"; +import { motion } from "motion/react"; +import React from "react"; +import { endsAt, getRuntime } from "@/utils/date/time"; + +import { useApiInContext } from "@/utils/store/api"; +import { useCarouselStore } from "@/utils/store/carousel"; +import { useCentralStore } from "@/utils/store/central"; import LikeButton from "../buttons/likeButton"; import MarkPlayedButton from "../buttons/markPlayedButton"; import PlayButton from "../buttons/playButton"; +import { getTypeIcon } from "../utils/iconsCollection"; + +const textVariants = { + initial: (direction: string) => ({ + x: direction === "right" ? 40 : -40, + opacity: 0, + }), + animate: { + x: 0, + opacity: 1, + transition: { + duration: 0.35, + ease: [0.2, 0, 0, 1], + }, + }, + exit: (direction: string) => ({ + x: direction === "right" ? -40 : 40, + opacity: 0, + transition: { + duration: 0.2, + ease: "easeInOut", + }, + }), +}; const CarouselSlide = ({ item }: { item: BaseItemDto }) => { const api = useApiInContext((s) => s.api); @@ -66,7 +84,13 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => { return (
-
+ {item.BackdropImageTags?.length ? ( {item.Name { {getTypeIcon(item.Type ?? "Movie")}
)} -
-
+ + + {/* @ts-ignore */} {!item.ImageTags?.Logo ? ( @@ -142,31 +166,11 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => { /> )} + {/* @ts-ignore */} { > {item.PremiereDate && ( - {item.ProductionYear} + {item.ProductionYear ?? ""} )} {item.OfficialRating && ( @@ -239,82 +243,49 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
)} - {item.RunTimeTicks ? ( + {item.RunTimeTicks && ( {getRuntime(item.RunTimeTicks)} - ) : ( - <> )} - {item.RunTimeTicks ? ( + {item.RunTimeTicks && ( {endsAt( item.RunTimeTicks - (item.UserData?.PlaybackPositionTicks ?? 0), )} - ) : ( - <> )} {item.Genres?.slice(0, 4).join(" / ")} + {/* @ts-ignore */} {item.Overview} + {/* @ts-ignore */} {