Files
Blink/src/components/carouselSlide/index.tsx
T
1xDed ae5a2133fa
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
chore: window resize handles, UI cleanup and type fixes
Adds edge resize handles for frameless Windows/Linux windows, reserves space for the custom titlebar, and fixes assorted unused imports, error-boundary typing and image decoding hints.
2026-11-28 01:37:33 +03:00

348 lines
8.4 KiB
TypeScript

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 { useQuery } from "@tanstack/react-query";
import { motion, type Variants } from "motion/react";
import React from "react";
import { endsAt, getRuntime } from "@/utils/date/time";
import {
getHeroPosterUrl,
getItemImagesQueryOptions,
resolveHeroArtwork,
} from "@/utils/methods/heroArtwork";
import BlurhashCanvas from "../blurhash-canvas";
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";
import { getItemLinkOptions } from "@/utils/navigation/itemLink";
const MotionTypography = motion.create(Typography);
const MotionStack = motion.create(Stack);
const textVariants: Variants = {
// No hidden start state: hero text must not blink on slide changes.
initial: {
x: 0,
opacity: 1,
},
animate: {
x: 0,
opacity: 1,
transition: {
duration: 0.35,
ease: [0.2, 0, 0, 1] as const,
},
},
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);
const navigate = useNavigate();
const user = useCentralStore((s) => s.currentUser);
const handleMoreInfo = () => {
if (item.Id) {
navigate(getItemLinkOptions(item.Id, item.Type));
}
};
const [animationDirection] = useCarouselStore((state) => [state.direction]);
// Jellyfin stores several images per item (poster, thumb, backdrops).
// Ask the server which ones exist and their real size, then pick the wide one.
const imageInfos = useQuery(getItemImagesQueryOptions(api, item.Id));
const heroArtwork = resolveHeroArtwork(api, item, imageInfos.data);
const heroPoster = heroArtwork?.isPortrait
? getHeroPosterUrl(api, item)
: undefined;
return (
<div className="hero-carousel-slide">
<motion.div
className="hero-carousel-background-container"
initial={{ opacity: 1 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.4, ease: "easeInOut" }}
>
{heroArtwork?.blurhash && (
<BlurhashCanvas
blurhashString={heroArtwork.blurhash}
width={48}
height={27}
canvasProps={{
className: "hero-carousel-background-blurhash",
}}
/>
)}
{heroArtwork ? (
<img
alt={item.Name ?? "item"}
className={`hero-carousel-background-image${heroArtwork.isPortrait ? " is-poster" : ""}`}
src={heroArtwork.url}
loading="eager"
decoding="async"
/>
) : (
<div className="hero-carousel-background-icon-container">
{getTypeIcon(item.Type ?? "Movie")}
</div>
)}
{heroPoster && (
<img
alt={item.Name ?? "poster"}
className="hero-carousel-poster"
src={heroPoster}
loading="eager"
/>
)}
</motion.div>
<motion.div
className="hero-carousel-detail"
initial="initial"
animate="animate"
exit="exit"
variants={{
animate: {
transition: {
staggerChildren: 0.05,
delayChildren: 0.05,
},
},
exit: {
transition: {
staggerChildren: 0.02,
staggerDirection: -1,
},
},
}}
>
<MotionStack
custom={animationDirection}
variants={textVariants}
direction="row"
sx={{ alignItems: "center", gap: 1 }}
>
<span className="hero-carousel-label">
{item.UserData?.PlaybackPositionTicks
? "Continue watching"
: item.Type === BaseItemKind.Series
? "New series"
: "New movie"}
</span>
</MotionStack>
<MotionTypography
custom={animationDirection}
variants={textVariants}
key={item.Id}
variant="h2"
className="hero-carousel-text"
sx={{
fontWeight: 600,
overflow: "visible",
}}
>
{item.Name}
</MotionTypography>
<MotionStack
custom={animationDirection}
variants={textVariants}
direction="row"
className="hero-carousel-info"
sx={{
gap: 2,
mt: 1,
justifyItems: "flex-start",
alignItems: "center",
}}
>
{item.PremiereDate && (
<Typography style={{ opacity: "0.8" }} variant="subtitle2">
{item.ProductionYear ?? ""}
</Typography>
)}
{item.OfficialRating && (
<Chip variant="filled" size="small" label={item.OfficialRating} />
)}
{item.CommunityRating && (
<div
style={{
display: "flex",
gap: "0.25em",
alignItems: "center",
}}
className="hero-carousel-info-rating"
>
<div
className="material-symbols-rounded fill"
style={{
// fontSize: "2.2em",
color: yellow[400],
}}
>
star
</div>
<Typography
style={{
opacity: "0.8",
}}
variant="subtitle2"
>
{Math.round(item.CommunityRating * 10) / 10}
</Typography>
</div>
)}
{item.CriticRating && (
<div
style={{
display: "flex",
gap: "0.25em",
alignItems: "center",
}}
className="hero-carousel-info-rating"
>
<div
className="material-symbols-rounded fill"
style={{
color: item.CriticRating > 50 ? green[400] : red[400],
}}
>
{item.CriticRating > 50 ? "thumb_up" : "thumb_down"}
</div>
<Typography
style={{
opacity: "0.8",
}}
variant="subtitle2"
>
{item.CriticRating}
</Typography>
</div>
)}
{item.RunTimeTicks && (
<Typography style={{ opacity: "0.8" }} variant="subtitle2">
{getRuntime(item.RunTimeTicks)}
</Typography>
)}
{item.RunTimeTicks && (
<Typography style={{ opacity: "0.8" }} variant="subtitle2">
{endsAt(
item.RunTimeTicks - (item.UserData?.PlaybackPositionTicks ?? 0),
)}
</Typography>
)}
<Typography variant="subtitle2" style={{ opacity: 0.8 }}>
{item.Genres?.slice(0, 4).join(" / ")}
</Typography>
</MotionStack>
<MotionTypography
custom={animationDirection}
variants={textVariants}
className="hero-carousel-overview"
variant="body1"
sx={{
fontWeight: 400,
}}
>
{item.Overview}
</MotionTypography>
<MotionStack
direction="row"
className="hero-carousel-button-container"
custom={animationDirection}
variants={textVariants}
sx={{
gap: 2,
width: "100%",
alignItems: "center",
}}
>
<PlayButton
item={item}
userId={user?.Id}
itemType={item.Type ?? "Movie"}
buttonProps={{
size: "large",
}}
audio={
item.Type === BaseItemKind.MusicAlbum ||
item.Type === BaseItemKind.Audio ||
item.Type === BaseItemKind.AudioBook ||
item.Type === BaseItemKind.Playlist
}
playlistItem={item.Type === BaseItemKind.Playlist}
playlistItemId={item.Id}
/>
<Button
size="large"
//@ts-expect-error
color="white"
variant="outlined"
endIcon={
<div
className="material-symbols-rounded"
style={{
fontSize: "2em",
}}
>
chevron_right
</div>
}
onClick={handleMoreInfo}
>
More info
</Button>
<Stack
direction="row"
sx={{
gap: 1,
}}
>
<LikeButton
itemId={item.Id}
queryKey={["home", "latestMedia"]}
userId={user?.Id}
isFavorite={item.UserData?.IsFavorite}
itemName={item.Name}
/>
<MarkPlayedButton
itemId={item.Id}
queryKey={["home", "latestMedia"]}
userId={user?.Id}
isPlayed={item.UserData?.Played}
itemName={item.Name}
/>
</Stack>
</MotionStack>
</motion.div>
</div>
);
};
export default CarouselSlide;