Backend: Added director column to Entry model, set during creation and refresh. Maintenance endpoint to scan/fix missing directors. Reverted expensive credit JOIN in getAllEntries. Frontend: @director: search prefix for Library and Watchlist. Director rendered on EntryDetailsPage via useEntryCredits. Fixed home page cards to link directly to EntryDetailsPage when entry is in library. Added TmdbCastsPage for TMDB cast browsing. Persisted collection sort order and gray-out-unseen toggle. Tooltip component now theme-aware.
239 lines
7.4 KiB
TypeScript
239 lines
7.4 KiB
TypeScript
import { useState, useEffect } from "react";
|
|
import {
|
|
useTrendingMovies,
|
|
useTrendingTv,
|
|
usePopularMovies,
|
|
usePopularTv,
|
|
useTopRatedMovies,
|
|
useTopRatedTv,
|
|
useUpcomingMovies,
|
|
} from "@/hooks/useTmdb";
|
|
import { useLibrary } from "@/hooks/useEntries";
|
|
import { TrendingUp, Play, Award, Calendar } from "lucide-react";
|
|
import {
|
|
HeroSlider,
|
|
BackdropCard,
|
|
NumberedListItem,
|
|
MiniPosterCard,
|
|
UpcomingCard,
|
|
SectionHeader,
|
|
PopularBelt,
|
|
} from "@/components/home";
|
|
|
|
export function HomePage() {
|
|
useLibrary();
|
|
|
|
const trendingMovies = useTrendingMovies();
|
|
const trendingTv = useTrendingTv();
|
|
const popularMovies = usePopularMovies();
|
|
const popularTv = usePopularTv();
|
|
const topRatedMovies = useTopRatedMovies();
|
|
const topRatedTv = useTopRatedTv();
|
|
const upcomingMovies = useUpcomingMovies();
|
|
|
|
const trendingMovieEntries =
|
|
trendingMovies.data?.pages.flatMap((p) => p.results) ?? [];
|
|
const trendingTvEntries =
|
|
trendingTv.data?.pages.flatMap((p) => p.results) ?? [];
|
|
const popularMovieEntries =
|
|
popularMovies.data?.pages.flatMap((p) => p.results) ?? [];
|
|
const popularTvEntries =
|
|
popularTv.data?.pages.flatMap((p) => p.results) ?? [];
|
|
const topRatedMovieEntries =
|
|
topRatedMovies.data?.pages.flatMap((p) => p.results) ?? [];
|
|
const topRatedTvEntries =
|
|
topRatedTv.data?.pages.flatMap((p) => p.results) ?? [];
|
|
const upcomingMovieEntries =
|
|
upcomingMovies.data?.pages.flatMap((p) => p.results) ?? [];
|
|
|
|
// Trending grid auto-rotation: exit -> swap -> enter
|
|
const [trendingIdx, setTrendingIdx] = useState(0);
|
|
const [trendingPhase, setTrendingPhase] = useState<"idle" | "exit" | "enter">(
|
|
"idle",
|
|
);
|
|
const trendingPool = trendingMovieEntries.slice(2);
|
|
const visibleTrending =
|
|
trendingPool.length >= 4
|
|
? [0, 1, 2, 3].map(
|
|
(offset) =>
|
|
trendingPool[(trendingIdx + offset) % trendingPool.length],
|
|
)
|
|
: trendingPool;
|
|
|
|
useEffect(() => {
|
|
if (trendingPool.length <= 4) return;
|
|
const timer = setInterval(() => {
|
|
setTrendingPhase("exit");
|
|
setTimeout(() => {
|
|
setTrendingIdx((i) => i + 1);
|
|
setTrendingPhase("enter");
|
|
setTimeout(() => setTrendingPhase("idle"), 600);
|
|
}, 380);
|
|
}, 7000);
|
|
return () => clearInterval(timer);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [trendingPool.length]);
|
|
|
|
const isLoading =
|
|
trendingMovies.isLoading ||
|
|
popularMovies.isLoading ||
|
|
topRatedMovies.isLoading ||
|
|
upcomingMovies.isLoading;
|
|
|
|
if (isLoading) {
|
|
return <HomeLoadingSkeleton />;
|
|
}
|
|
|
|
return (
|
|
<div className="animate-page-enter space-y-12 pb-12">
|
|
{/* Hero Slider — full bleed */}
|
|
<div className="-mx-4 -mt-18 md:-mx-6 md:-mt-6">
|
|
<HeroSlider entries={trendingMovieEntries} />
|
|
</div>
|
|
|
|
{/* Trending Now */}
|
|
<section className="space-y-5">
|
|
<SectionHeader
|
|
icon={<TrendingUp className="h-5 w-5 text-rose-500" />}
|
|
title="Trending Now"
|
|
category="trending"
|
|
/>
|
|
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6">
|
|
{/* Rotating 2x2 backdrop grid */}
|
|
<div
|
|
className="xl:col-span-2 grid grid-cols-1 sm:grid-cols-2 gap-4 overflow-hidden"
|
|
style={{
|
|
opacity: trendingPhase === "exit" ? 0 : 1,
|
|
transform:
|
|
trendingPhase === "exit"
|
|
? "translateX(-28px)"
|
|
: "translateX(0)",
|
|
transition:
|
|
trendingPhase === "exit"
|
|
? "opacity 380ms ease, transform 380ms ease"
|
|
: "none",
|
|
}}
|
|
>
|
|
{visibleTrending.map((item, i) => (
|
|
<BackdropCard
|
|
key={`${item.id}-${trendingIdx}`}
|
|
entry={item}
|
|
animClass={
|
|
trendingPhase === "enter"
|
|
? "animate-slide-from-right"
|
|
: undefined
|
|
}
|
|
animDelay={trendingPhase === "enter" ? i * 90 : 0}
|
|
/>
|
|
))}
|
|
</div>
|
|
{/* Numbered TV list */}
|
|
<div className="space-y-1">
|
|
<p className="text-xs uppercase tracking-widest text-muted-foreground font-semibold mb-3">
|
|
Trending TV
|
|
</p>
|
|
{trendingTvEntries.slice(0, 8).map((item, i) => (
|
|
<NumberedListItem key={item.id} entry={item} rank={i + 1} />
|
|
))}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
{/* Popular Right Now — infinite belt */}
|
|
<section className="space-y-5">
|
|
<SectionHeader
|
|
icon={<Play className="h-5 w-5 text-blue-500" />}
|
|
title="Popular Right Now"
|
|
category="popular"
|
|
/>
|
|
<PopularBelt
|
|
movieEntries={popularMovieEntries}
|
|
tvEntries={popularTvEntries}
|
|
/>
|
|
</section>
|
|
|
|
{/* Top Rated */}
|
|
<section className="space-y-5">
|
|
<SectionHeader
|
|
icon={<Award className="h-5 w-5 text-yellow-500" />}
|
|
title="Top Rated"
|
|
category="top-rated"
|
|
/>
|
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
|
<div className="space-y-4">
|
|
<p className="text-xs uppercase tracking-widest text-muted-foreground font-semibold">
|
|
Movies
|
|
</p>
|
|
{topRatedMovieEntries[0] && (
|
|
<BackdropCard entry={topRatedMovieEntries[0]} showRating />
|
|
)}
|
|
<div className="grid grid-cols-4 gap-3">
|
|
{topRatedMovieEntries.slice(1, 5).map((item) => (
|
|
<MiniPosterCard key={item.id} entry={item} hideTitle />
|
|
))}
|
|
</div>
|
|
</div>
|
|
<div className="space-y-4">
|
|
<p className="text-xs uppercase tracking-widest text-muted-foreground font-semibold">
|
|
TV Shows
|
|
</p>
|
|
<div className="space-y-1">
|
|
{topRatedTvEntries.slice(0, 10).map((item, i) => (
|
|
<NumberedListItem key={item.id} entry={item} rank={i + 1} />
|
|
))}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
{/* Coming Soon */}
|
|
<section className="space-y-5">
|
|
<SectionHeader
|
|
icon={<Calendar className="h-5 w-5 text-emerald-500" />}
|
|
title="Coming Soon"
|
|
category="upcoming"
|
|
/>
|
|
<div
|
|
className="flex gap-3 overflow-x-auto pb-2"
|
|
style={
|
|
{
|
|
scrollbarWidth: "none",
|
|
msOverflowStyle: "none",
|
|
} as React.CSSProperties
|
|
}
|
|
>
|
|
{upcomingMovieEntries.slice(0, 14).map((item) => (
|
|
<UpcomingCard key={item.id} entry={item} />
|
|
))}
|
|
</div>
|
|
</section>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function HomeLoadingSkeleton() {
|
|
return (
|
|
<div className="animate-pulse space-y-12 pb-12">
|
|
<div className="-mx-4 -mt-18 md:-mx-6 md:-mt-6">
|
|
<div
|
|
className="w-full bg-muted"
|
|
style={{ aspectRatio: "16/9", maxHeight: "70vh" }}
|
|
/>
|
|
</div>
|
|
<div className="space-y-4">
|
|
<div className="h-6 w-48 rounded bg-muted" />
|
|
<div className="grid grid-cols-2 gap-4">
|
|
<div
|
|
className="rounded-xl bg-muted"
|
|
style={{ aspectRatio: "16/9" }}
|
|
/>
|
|
<div
|
|
className="rounded-xl bg-muted"
|
|
style={{ aspectRatio: "16/9" }}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|