feat(home): cinematic rounded home page with integrated hero
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
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
Home is now a floating rounded window: an integrated header over full-bleed artwork, a large featured title with actions, and a Trending now rail that switches the hero. Existing home sections continue below in the same frame.
This commit is contained in:
1 parent
affbd00157
commit
d5c1bfac64
9 files changed
+873
-489
No files matched your search
@@ -1,23 +1,23 @@
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import type { Api } from "@jellyfin/sdk";
|
||||
|
||||
import { useCarouselStore } from "../../utils/store/carousel";
|
||||
import "./carousel.scss";
|
||||
import {
|
||||
type BaseItemDto,
|
||||
BaseItemKind,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { useCarouselStore } from "../../utils/store/carousel";
|
||||
import "./carousel.scss";
|
||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||
import { resolveItemImage } from "@/utils/methods/itemImages";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import CarouselSlide from "../carouselSlide";
|
||||
import CarouselTickers from "./tickers";
|
||||
|
||||
const AUTOPLAY_MS = 9000;
|
||||
|
||||
// Memoize CarouselSlide to prevent unnecessary re-renders
|
||||
const MemoizedCarouselSlide = React.memo(CarouselSlide);
|
||||
|
||||
/** Sidebar thumbnail: prefer Thumb, fall back to Backdrop/Primary when missing. */
|
||||
const tickerImageUrl = (
|
||||
/** Wide artwork for the trending rail, falling back through the item's images. */
|
||||
const trendingImageUrl = (
|
||||
api: Api,
|
||||
item: BaseItemDto,
|
||||
): string | undefined => {
|
||||
@@ -27,13 +27,19 @@ const tickerImageUrl = (
|
||||
image.itemId,
|
||||
image.imageType,
|
||||
{
|
||||
quality: 90,
|
||||
fillHeight: 360,
|
||||
quality: 85,
|
||||
fillWidth: 480,
|
||||
tag: image.tag,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const trendingLabel = (item: BaseItemDto): string => {
|
||||
const genre = item.Genres?.[0];
|
||||
if (genre) return genre.charAt(0).toUpperCase() + genre.slice(1);
|
||||
return item.Type === BaseItemKind.Series ? "Series" : "Movie";
|
||||
};
|
||||
|
||||
const Carousel = ({
|
||||
content,
|
||||
onChange,
|
||||
@@ -43,107 +49,136 @@ const Carousel = ({
|
||||
}) => {
|
||||
const [currentSlide, setCurrentSlide] = useState(0);
|
||||
const [isPaused, setIsPaused] = useState(false);
|
||||
const sidebarRef = React.useRef<HTMLDivElement>(null);
|
||||
const tickerRefs = React.useRef<(HTMLDivElement | null)[]>([]);
|
||||
const currentSlideRef = React.useRef(currentSlide);
|
||||
|
||||
const [setDirection] = useCarouselStore((state) => [state.setDirection]);
|
||||
const api = useApiInContext((s) => s.api);
|
||||
|
||||
const total = content.length;
|
||||
|
||||
useEffect(() => {
|
||||
currentSlideRef.current = currentSlide;
|
||||
}, [currentSlide]);
|
||||
if (currentSlide >= total && total > 0) {
|
||||
setCurrentSlide(total - 1);
|
||||
}
|
||||
}, [currentSlide, total]);
|
||||
|
||||
useEffect(() => {
|
||||
onChange(currentSlide);
|
||||
}, [currentSlide, onChange]);
|
||||
|
||||
// Auto-scroll sidebar to keep active item in view
|
||||
const activeTicker = tickerRefs.current[currentSlide];
|
||||
const sidebar = sidebarRef.current;
|
||||
|
||||
if (activeTicker && sidebar) {
|
||||
const sidebarTop = sidebar.scrollTop;
|
||||
const sidebarBottom = sidebarTop + sidebar.clientHeight;
|
||||
const activeTickerTop = activeTicker.offsetTop;
|
||||
const activeTickerBottom =
|
||||
activeTicker.offsetTop + activeTicker.offsetHeight;
|
||||
|
||||
// If element is below the visible area
|
||||
if (activeTickerBottom > sidebarBottom) {
|
||||
sidebar.scrollTo({
|
||||
top: activeTickerBottom - sidebar.clientHeight + 24, // 24px padding
|
||||
behavior: "smooth",
|
||||
});
|
||||
}
|
||||
// If element is above the visible area
|
||||
else if (activeTickerTop < sidebarTop) {
|
||||
sidebar.scrollTo({
|
||||
top: activeTickerTop - 24, // 24px padding
|
||||
behavior: "smooth",
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [currentSlide, content, onChange]);
|
||||
|
||||
// Autoplay functionality
|
||||
useEffect(() => {
|
||||
if (isPaused || content.length === 0) return;
|
||||
|
||||
const timer = setInterval(() => {
|
||||
setDirection("right");
|
||||
setCurrentSlide((prev) => (prev + 1) % content.length);
|
||||
}, 8000);
|
||||
|
||||
return () => clearInterval(timer);
|
||||
}, [isPaused, content.length, setDirection, currentSlide]);
|
||||
|
||||
const api = useApiInContext((s) => s.api);
|
||||
|
||||
const handleTickerClick = useCallback(
|
||||
const goTo = useCallback(
|
||||
(index: number) => {
|
||||
if (index === currentSlideRef.current) return;
|
||||
setDirection(index > currentSlideRef.current ? "right" : "left");
|
||||
if (index === currentSlide) return;
|
||||
setDirection(index > currentSlide ? "right" : "left");
|
||||
setCurrentSlide(index);
|
||||
},
|
||||
[setDirection],
|
||||
[currentSlide, setDirection],
|
||||
);
|
||||
|
||||
if (!api) return null;
|
||||
const next = useCallback(() => {
|
||||
if (total < 2) return;
|
||||
setDirection("right");
|
||||
setCurrentSlide((prev) => (prev + 1) % total);
|
||||
}, [total, setDirection]);
|
||||
|
||||
const previous = useCallback(() => {
|
||||
if (total < 2) return;
|
||||
setDirection("left");
|
||||
setCurrentSlide((prev) => (prev - 1 + total) % total);
|
||||
}, [total, setDirection]);
|
||||
|
||||
// Autoplay; pauses while the pointer is over the hero.
|
||||
useEffect(() => {
|
||||
if (isPaused || total < 2) return;
|
||||
const timer = window.setInterval(() => {
|
||||
setDirection("right");
|
||||
setCurrentSlide((prev) => (prev + 1) % total);
|
||||
}, AUTOPLAY_MS);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [isPaused, total, setDirection]);
|
||||
|
||||
if (!api || total === 0) return null;
|
||||
|
||||
const currentItem = content[currentSlide];
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`carousel ${isPaused ? "paused" : ""}`}
|
||||
<section
|
||||
className={`cinema-hero ${isPaused ? "paused" : ""}`}
|
||||
aria-roledescription="carousel"
|
||||
aria-label="Featured"
|
||||
onMouseEnter={() => setIsPaused(true)}
|
||||
onMouseLeave={() => setIsPaused(false)}
|
||||
>
|
||||
<div className="hero-carousel-slide-wrapper">
|
||||
<MemoizedCarouselSlide item={content[currentSlide]} />
|
||||
</div>
|
||||
<div className="carousel-sidebar" ref={sidebarRef}>
|
||||
{content.map((item, index) => (
|
||||
<div
|
||||
key={item.Id}
|
||||
ref={(el) => {
|
||||
tickerRefs.current[index] = el;
|
||||
}}
|
||||
className="carousel-ticker-wrapper"
|
||||
<MemoizedCarouselSlide key={currentItem.Id} item={currentItem} />
|
||||
|
||||
{total > 1 && (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
className="cinema-arrow left"
|
||||
onClick={previous}
|
||||
aria-label="Previous"
|
||||
>
|
||||
<CarouselTickers
|
||||
imageUrl={tickerImageUrl(api, item)}
|
||||
isActive={index === currentSlide}
|
||||
itemName={item.Name ?? "Unknown"}
|
||||
itemYear={
|
||||
item.Type === BaseItemKind.Series && item.EndDate
|
||||
? `${item.ProductionYear ?? ""} - ${new Date(item.EndDate).getFullYear().toString()}`
|
||||
: (item.ProductionYear?.toString() ?? "")
|
||||
}
|
||||
onTickerClick={handleTickerClick}
|
||||
index={index}
|
||||
itemType={item.Type as BaseItemKind}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
<span className="material-symbols-rounded">chevron_left</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="cinema-arrow right"
|
||||
onClick={next}
|
||||
aria-label="Next"
|
||||
>
|
||||
<span className="material-symbols-rounded">chevron_right</span>
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className="cinema-trending">
|
||||
<div className="cinema-trending-head">
|
||||
<h3>Trending now</h3>
|
||||
{total > 1 && (
|
||||
<div className="cinema-dots">
|
||||
{content.map((item, index) => (
|
||||
<button
|
||||
key={item.Id}
|
||||
type="button"
|
||||
className={index === currentSlide ? "active" : ""}
|
||||
onClick={() => goTo(index)}
|
||||
aria-label={item.Name ?? `Slide ${index + 1}`}
|
||||
aria-current={index === currentSlide}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="cinema-trending-rail">
|
||||
{content.map((item, index) => {
|
||||
const imageUrl = trendingImageUrl(api, item);
|
||||
return (
|
||||
<button
|
||||
key={item.Id}
|
||||
type="button"
|
||||
className={`cinema-trending-card ${
|
||||
index === currentSlide ? "active" : ""
|
||||
}`}
|
||||
onClick={() => goTo(index)}
|
||||
aria-label={item.Name ?? "Featured item"}
|
||||
>
|
||||
{imageUrl ? (
|
||||
<img src={imageUrl} alt="" loading="lazy" />
|
||||
) : (
|
||||
<div className="cinema-trending-placeholder">
|
||||
<span className="material-symbols-rounded">
|
||||
{ item.Type === BaseItemKind.Series ? "tv" : "movie" }
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<span className="cinema-trending-chip">
|
||||
{trendingLabel(item)}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user