feat(frontend): implement full in-app streaming system with 4 APIs

- Add streaming types, interfaces, and normalized response structures
- Create StreamingManager with URL building, validation, and security
- Implement provider adapters for VidLink (2 servers), VidKing (1 server), AnyEmbed (5 servers)
- Add Zustand streaming store with server selection, fallback, and retry logic
- Build StreamingPlayer iframe component with fullscreen and keyboard shortcuts
- Add ServerSelector dropdown with 8 servers and active state indicator
- Create EpisodeNavigator with season tabs and episode grid
- Implement AutoMarkWatchedPrompt for one-time completion opt-in
- Add StreamingSection with Watch Now / Continue Watching entry point
- Integrate StreamingSection into EntryDetailsPage
This commit is contained in:
Mohammed Abad committed 2026-05-25 02:09:40 +01:00
1 parent 1a2ec5c505
commit 54014ae01f
19 files changed
+2617

No files matched your search

@@ -38,6 +38,7 @@ import {
} from '@/components/ui/tooltip';
import { CastList } from '@/components/entries/CastList';
import { SeasonsContainer } from '@/components/entries/SeasonsContainer';
import { StreamingSection } from '@/components/streaming/StreamingSection';
// EpisodeWatchHistory is available for future use
import { EntrySettingsDialog } from '@/components/dialogs/EntrySettingsDialog';
import { EntrySeenDialog } from '@/components/dialogs/EntrySeenDialog';
@@ -410,6 +411,9 @@ export function EntryDetailsPage() {
{/* Sections */}
<div className="mt-10 space-y-8">
{/* Streaming player */}
<StreamingSection entry={e} seasons={seasons} />
{e.credits && e.credits.length > 0 && (
<>
<Separator />
+293
View File
@@ -0,0 +1,293 @@
import { useRef } from 'react';
import { Link } from 'react-router-dom';
import {
useTrendingMovies,
useTrendingTv,
usePopularMovies,
usePopularTv,
useTopRatedMovies,
useTopRatedTv,
useUpcomingMovies,
} from '@/hooks/useTmdb';
import { useLibrary } from '@/hooks/useEntries';
import { useCreateEntry } from '@/hooks/useEntries';
import { useLibraryStore } from '@/stores/useLibraryStore';
import { Button } from '@/components/ui/button';
import { ChevronLeft, ChevronRight, Star, Play, Plus } from 'lucide-react';
import type { TmdbEntry } from '@/types';
/**
* HomePage2 — Netflix-style layout
* - Full-bleed hero with featured trending item
* - Horizontal scroll rows per category (poster cards)
* - No tabs: movies first, then TV in separate rows
*/
export function HomePage2() {
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) ?? [];
const heroItem = trendingMovieEntries[0];
const isLoading = trendingMovies.isLoading;
return (
<div className="animate-page-enter -mx-6 -mt-6">
{/* Hero Section */}
<HeroSpotlight item={heroItem} isLoading={isLoading} />
{/* Scrollable Rows */}
<div className="space-y-8 px-6 pt-8 pb-12">
<ScrollRow
title="Trending Movies"
entries={trendingMovieEntries.slice(1, 20)}
isLoading={trendingMovies.isLoading}
category="trending"
/>
<ScrollRow
title="Trending TV Shows"
entries={trendingTvEntries.slice(0, 20)}
isLoading={trendingTv.isLoading}
category="trending"
/>
<ScrollRow
title="Popular Movies"
entries={popularMovieEntries.slice(0, 20)}
isLoading={popularMovies.isLoading}
category="popular"
/>
<ScrollRow
title="Popular TV Shows"
entries={popularTvEntries.slice(0, 20)}
isLoading={popularTv.isLoading}
category="popular"
/>
<ScrollRow
title="Top Rated Movies"
entries={topRatedMovieEntries.slice(0, 20)}
isLoading={topRatedMovies.isLoading}
category="top-rated"
/>
<ScrollRow
title="Top Rated TV Shows"
entries={topRatedTvEntries.slice(0, 20)}
isLoading={topRatedTv.isLoading}
category="top-rated"
/>
<ScrollRow
title="Upcoming Movies"
entries={upcomingMovieEntries.slice(0, 20)}
isLoading={upcomingMovies.isLoading}
category="upcoming"
/>
</div>
</div>
);
}
/* ─── Hero Spotlight ──────────────────────────────────────────────── */
function HeroSpotlight({ item, isLoading }: { item?: TmdbEntry; isLoading: boolean }) {
const createEntry = useCreateEntry();
const libraryEntries = useLibraryStore((s) => s.entries);
if (isLoading || !item) {
return <div className="h-[70vh] bg-muted animate-pulse" />;
}
const title = item.title || item.name || 'Untitled';
const backdrop = item.backdrop_path
? `https://image.tmdb.org/t/p/original${item.backdrop_path}`
: null;
const isTv = item.media_type === 'tv' || !!item.name;
const matchedEntry = Array.from(libraryEntries.values()).find(
(e) => e.entryIds?.tmdb_id === item.id
);
return (
<div className="relative h-[70vh] min-h-125">
{backdrop && (
<img
src={backdrop}
alt=""
className="absolute inset-0 h-full w-full object-cover"
/>
)}
{/* Gradient overlays */}
<div className="absolute inset-0 bg-linear-to-r from-black/80 via-black/40 to-transparent" />
<div className="absolute inset-0 bg-linear-to-t from-background via-transparent to-transparent" />
{/* Content */}
<div className="absolute bottom-16 left-8 sm:left-12 z-10 max-w-xl space-y-4">
<div className="flex items-center gap-2 text-white/60 text-xs uppercase tracking-widest font-medium">
<span>{isTv ? 'TV Series' : 'Movie'}</span>
{item.vote_average > 0 && (
<span className="flex items-center gap-1 text-yellow-400">
<Star className="h-3 w-3 fill-current" />
{item.vote_average.toFixed(1)}
</span>
)}
</div>
<h1 className="text-4xl sm:text-6xl font-black text-white leading-none tracking-tight">
{title}
</h1>
{item.overview && (
<p className="text-sm sm:text-base text-white/70 line-clamp-3 leading-relaxed">
{item.overview}
</p>
)}
<div className="flex items-center gap-3 pt-2">
{matchedEntry ? (
<Link to={`/entry/${matchedEntry.id}`}>
<Button size="lg" className="rounded-full gap-2 px-6 font-semibold">
<Play className="h-4 w-4 fill-current" />
View Details
</Button>
</Link>
) : (
<Button
size="lg"
className="rounded-full gap-2 px-6 font-semibold"
onClick={() => createEntry.mutate({ tmdb_id: item.id, is_tvserie: isTv })}
disabled={createEntry.isPending}
>
<Plus className="h-4 w-4" />
Add to Library
</Button>
)}
</div>
</div>
</div>
);
}
/* ─── Horizontal Scroll Row ───────────────────────────────────────── */
function ScrollRow({
title,
entries,
isLoading,
category,
}: {
title: string;
entries: TmdbEntry[];
isLoading: boolean;
category: string;
}) {
const scrollRef = useRef<HTMLDivElement>(null);
const scroll = (direction: 'left' | 'right') => {
if (!scrollRef.current) return;
const amount = scrollRef.current.clientWidth * 0.75;
scrollRef.current.scrollBy({
left: direction === 'left' ? -amount : amount,
behavior: 'smooth',
});
};
if (isLoading) {
return (
<div className="space-y-3">
<div className="h-6 w-48 bg-muted rounded animate-pulse" />
<div className="flex gap-3 overflow-hidden">
{Array.from({ length: 8 }).map((_, i) => (
<div key={i} className="w-37.5 h-56.25 shrink-0 bg-muted rounded-lg animate-pulse" />
))}
</div>
</div>
);
}
return (
<div className="space-y-3 group/row">
<div className="flex items-center justify-between">
<h3 className="text-lg font-semibold">{title}</h3>
<Link
to={`/discover/${category}`}
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
>
See All →
</Link>
</div>
<div className="relative">
{/* Scroll buttons */}
<button
onClick={() => scroll('left')}
className="absolute -left-3 top-1/2 -translate-y-1/2 z-10 h-10 w-10 rounded-full bg-background/90 border shadow-lg flex items-center justify-center opacity-0 group-hover/row:opacity-100 transition-opacity hover:bg-accent"
>
<ChevronLeft className="h-5 w-5" />
</button>
<button
onClick={() => scroll('right')}
className="absolute -right-3 top-1/2 -translate-y-1/2 z-10 h-10 w-10 rounded-full bg-background/90 border shadow-lg flex items-center justify-center opacity-0 group-hover/row:opacity-100 transition-opacity hover:bg-accent"
>
<ChevronRight className="h-5 w-5" />
</button>
{/* Cards */}
<div
ref={scrollRef}
className="flex gap-3 overflow-x-auto scrollbar-hide scroll-smooth pb-2"
>
{entries.map((entry) => (
<PosterCard key={entry.id} entry={entry} />
))}
</div>
</div>
</div>
);
}
/* ─── Poster Card ─────────────────────────────────────────────────── */
function PosterCard({ entry }: { entry: TmdbEntry }) {
const title = entry.title || entry.name || 'Untitled';
const poster = entry.poster_path
? `https://image.tmdb.org/t/p/w342${entry.poster_path}`
: null;
const isTv = entry.media_type === 'tv' || !!entry.name;
const linkTo = `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${entry.id}`;
return (
<Link
to={linkTo}
className="group/card shrink-0 w-37.5 space-y-2 transition-transform hover:scale-105"
>
<div className="relative aspect-2/3 rounded-lg overflow-hidden bg-muted">
{poster ? (
<img src={poster} alt={title} className="h-full w-full object-cover" />
) : (
<div className="h-full w-full flex items-center justify-center text-muted-foreground text-xs">
No Image
</div>
)}
{/* Hover overlay */}
<div className="absolute inset-0 bg-black/0 group-hover/card:bg-black/40 transition-colors flex items-center justify-center">
<Play className="h-8 w-8 text-white opacity-0 group-hover/card:opacity-100 transition-opacity fill-current" />
</div>
{/* Rating badge */}
{entry.vote_average > 0 && (
<div className="absolute top-2 right-2 bg-black/70 backdrop-blur-sm rounded-full px-1.5 py-0.5 flex items-center gap-0.5 text-[10px] text-yellow-400 font-medium">
<Star className="h-2.5 w-2.5 fill-current" />
{entry.vote_average.toFixed(1)}
</div>
)}
</div>
<p className="text-sm font-medium truncate">{title}</p>
</Link>
);
}
+661
View File
@@ -0,0 +1,661 @@
import { useState, useEffect, useRef } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import {
useTrendingMovies,
useTrendingTv,
usePopularMovies,
usePopularTv,
useTopRatedMovies,
useTopRatedTv,
useUpcomingMovies,
} from '@/hooks/useTmdb';
import { useLibrary, useCreateEntry } from '@/hooks/useEntries';
import { useLibraryStore } from '@/stores/useLibraryStore';
import { Button } from '@/components/ui/button';
import {
Star,
Plus,
Play,
TrendingUp,
Award,
Calendar,
Search,
ChevronLeft,
ChevronRight,
} from 'lucide-react';
import type { TmdbEntry } from '@/types';
export function HomePage3() {
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(() => {
// 1. Slide existing cards out to the left
setTrendingPhase('exit');
setTimeout(() => {
// 2. Swap in next set
setTrendingIdx((i) => i + 1);
setTrendingPhase('enter');
// 3. Return to idle after enter animation finishes
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 <LoadingSkeleton />;
}
return (
<div className="animate-page-enter space-y-12 pb-12">
{/* ─── Hero Slider — bleeds full width, breaks out of container padding ─── */}
<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">
{/* 2x2 backdrop grid — slides out left, new set slides in from right */}
<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 moving belt ─────────────────── */}
<section className="space-y-5">
<SectionHeader
icon={<Play className="h-5 w-5 text-blue-500" />}
title="Popular Right Now"
category="popular"
/>
{/* Overflow clip so the belt bleeds edge-to-edge within the section */}
<div className="overflow-hidden">
<div
className="flex gap-4"
style={{
animation: 'marquee-left 40s linear infinite',
width: 'max-content',
}}
onMouseEnter={(e) => ((e.currentTarget as HTMLDivElement).style.animationPlayState = 'paused')}
onMouseLeave={(e) => ((e.currentTarget as HTMLDivElement).style.animationPlayState = 'running')}
>
{/* Original + duplicate for seamless loop */}
{[...Array(2)].flatMap((_, pass) =>
[...popularMovieEntries.slice(0, 8), ...popularTvEntries.slice(0, 6)].map((item) => (
<BackdropScrollCard key={`${pass}-${item.id}`} entry={item} />
))
)}
</div>
</div>
</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 — horizontal scroll, small cards ─────────────── */}
<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>
);
}
/* ─── Hero Slider ───────────────────────────────────────────────────── */
function HeroSlider({ entries }: { entries: TmdbEntry[] }) {
const navigate = useNavigate();
const [activeIndex, setActiveIndex] = useState(0);
const [searchInput, setSearchInput] = useState('');
const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
const createEntry = useCreateEntry();
const libraryEntries = useLibraryStore((s) => s.entries);
const slides = entries.slice(0, 8);
const go = (idx: number) => {
setActiveIndex((idx + slides.length) % slides.length);
};
const startAutoplay = () => {
if (intervalRef.current) clearInterval(intervalRef.current);
if (slides.length === 0) return;
intervalRef.current = setInterval(
() => setActiveIndex((i) => (i + 1) % slides.length),
6000,
);
};
useEffect(() => {
startAutoplay();
return () => {
if (intervalRef.current) clearInterval(intervalRef.current);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [slides.length]);
const handleSearch = () => {
const q = searchInput.trim();
if (q) navigate(`/search?q=${encodeURIComponent(q)}`);
};
if (slides.length === 0) return null;
return (
<div
className="relative w-full overflow-hidden"
style={{ aspectRatio: '16/9', maxHeight: '70vh' }}
>
{/* ── Slide track — full-width flex rail that translates on index change ── */}
<div
className="flex h-full transition-transform duration-700 ease-in-out will-change-transform"
style={{
width: `${slides.length * 100}%`,
transform: `translateX(calc(-${activeIndex} / ${slides.length} * 100%))`,
}}
>
{slides.map((entry) => {
const title = entry.title || entry.name || 'Untitled';
const backdrop = entry.backdrop_path
? `https://image.tmdb.org/t/p/original${entry.backdrop_path}`
: null;
const isTv = entry.media_type === 'tv' || !!entry.name;
const matchedEntry = Array.from(libraryEntries.values()).find(
(e) => e.entryIds?.tmdb_id === entry.id,
);
return (
<div
key={entry.id}
className="relative h-full shrink-0"
style={{ width: `${100 / slides.length}%` }}
>
{backdrop ? (
<img
src={backdrop}
alt=""
className="absolute inset-0 h-full w-full object-cover rounded-none"
/>
) : (
<div className="absolute inset-0 bg-linear-to-br from-primary/20 to-muted" />
)}
<div className="absolute inset-0 bg-linear-to-t from-black/90 via-black/20 to-black/50" />
{/* Per-slide info — slides with the track */}
<div className="absolute bottom-0 left-0 right-0 z-10 space-y-2 px-4 pb-5 md:px-6 md:pb-8">
<div className="flex items-center gap-2">
<span className="rounded-full bg-white/10 px-2 py-0.5 text-[10px] font-bold uppercase tracking-widest text-white/60 backdrop-blur-sm">
{isTv ? 'Series' : 'Movie'}
</span>
{entry.vote_average > 0 && (
<span className="flex items-center gap-1 text-xs text-yellow-400">
<Star className="h-3 w-3 fill-current" />
{entry.vote_average.toFixed(1)}
</span>
)}
</div>
<h2 className="text-2xl font-black leading-tight text-white drop-shadow-lg md:text-4xl">
{title}
</h2>
{entry.overview && (
<p className="line-clamp-2 max-w-lg text-xs text-white/60 md:text-sm">
{entry.overview}
</p>
)}
<div className="flex gap-2 pt-1">
{matchedEntry ? (
<Link to={`/entry/${matchedEntry.id}`}>
<Button size="sm" variant="secondary" className="rounded-full gap-1.5 text-xs">
<Play className="h-3 w-3 fill-current" />
Details
</Button>
</Link>
) : (
<Button
size="sm"
variant="secondary"
className="rounded-full gap-1.5 text-xs"
onClick={() => createEntry.mutate({ tmdb_id: entry.id, is_tvserie: isTv })}
disabled={createEntry.isPending}
>
<Plus className="h-3 w-3" />
Add
</Button>
)}
</div>
</div>
</div>
);
})}
</div>
{/* ── Search bar — fixed top-center overlay ── */}
<div className="absolute top-5 left-1/2 z-20 w-full max-w-sm -translate-x-1/2 px-4">
<div className="relative">
<Search className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-white/60" />
<input
type="text"
placeholder="Search movies, TV shows..."
value={searchInput}
onChange={(e) => setSearchInput(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && handleSearch()}
className="w-full rounded-full border border-white/20 bg-black/40 py-2.5 pl-9 pr-4 text-sm text-white backdrop-blur-md placeholder-white/50 transition-colors focus:border-white/50 focus:outline-none"
/>
</div>
</div>
{/* ── Left arrow ── */}
<button
className="absolute left-3 top-1/2 z-20 flex h-9 w-9 -translate-y-1/2 items-center justify-center rounded-full border border-white/10 bg-black/30 text-white backdrop-blur-sm transition-colors hover:bg-black/60"
onClick={() => { go(activeIndex - 1); startAutoplay(); }}
aria-label="Previous"
>
<ChevronLeft className="h-5 w-5" />
</button>
{/* ── Right arrow ── */}
<button
className="absolute right-3 top-1/2 z-20 flex h-9 w-9 -translate-y-1/2 items-center justify-center rounded-full border border-white/10 bg-black/30 text-white backdrop-blur-sm transition-colors hover:bg-black/60"
onClick={() => { go(activeIndex + 1); startAutoplay(); }}
aria-label="Next"
>
<ChevronRight className="h-5 w-5" />
</button>
{/* ── Dot indicators — fixed bottom-right overlay ── */}
<div className="absolute bottom-5 right-4 z-20 flex items-center gap-1.5 md:bottom-8 md:right-6">
{slides.map((_, i) => (
<button
key={i}
onClick={() => { go(i); startAutoplay(); }}
aria-label={`Go to slide ${i + 1}`}
className={`rounded-full transition-all duration-300 ${
i === activeIndex
? 'h-1.5 w-6 bg-white'
: 'h-1.5 w-1.5 bg-white/30 hover:bg-white/60'
}`}
/>
))}
</div>
</div>
);
}
/* ─── Backdrop Card (16:9, used in grids) ───────────────────────────── */
function BackdropCard({
entry,
showRating,
animClass,
animDelay,
}: {
entry: TmdbEntry;
showRating?: boolean;
animClass?: string;
animDelay?: number;
}) {
const title = entry.title || entry.name || 'Untitled';
const backdrop = entry.backdrop_path
? `https://image.tmdb.org/t/p/w780${entry.backdrop_path}`
: null;
const isTv = entry.media_type === 'tv' || !!entry.name;
const linkTo = `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${entry.id}`;
return (
<Link
to={linkTo}
className={`group relative block overflow-hidden rounded-xl bg-muted ${animClass ?? 'animate-page-enter'}`}
style={{ aspectRatio: '16/9', animationDelay: animDelay ? `${animDelay}ms` : undefined }}
>
{backdrop ? (
<img
src={backdrop}
alt={title}
className="absolute inset-0 h-full w-full object-cover transition-transform duration-300 group-hover:scale-105"
/>
) : (
<div className="absolute inset-0 bg-linear-to-br from-muted-foreground/20 to-muted" />
)}
<div className="absolute inset-0 bg-linear-to-t from-black/80 via-black/10 to-transparent" />
<div className="absolute bottom-0 left-0 right-0 p-3">
<p className="truncate text-sm font-semibold text-white">{title}</p>
{showRating && entry.vote_average > 0 && (
<span className="mt-0.5 flex items-center gap-1 text-xs text-yellow-400">
<Star className="h-3 w-3 fill-current" />
{entry.vote_average.toFixed(1)}
</span>
)}
</div>
</Link>
);
}
/* ─── Backdrop Scroll Card (fixed width, for horizontal scroll row) ─── */
function BackdropScrollCard({
entry,
}: {
entry: TmdbEntry;
}) {
const title = entry.title || entry.name || 'Untitled';
const backdrop = entry.backdrop_path
? `https://image.tmdb.org/t/p/w780${entry.backdrop_path}`
: null;
const isTv = entry.media_type === 'tv' || !!entry.name;
const linkTo = `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${entry.id}`;
return (
<Link
to={linkTo}
className="group relative block shrink-0 overflow-hidden rounded-xl bg-muted"
style={{ width: '260px', aspectRatio: '16/9' }}
>
{backdrop ? (
<img
src={backdrop}
alt={title}
className="absolute inset-0 h-full w-full object-cover transition-transform duration-300 group-hover:scale-105"
/>
) : (
<div className="absolute inset-0 bg-linear-to-br from-muted-foreground/20 to-muted" />
)}
<div className="absolute inset-0 bg-linear-to-t from-black/80 via-black/10 to-transparent" />
<div className="absolute bottom-0 left-0 right-0 p-3">
<p className="truncate text-sm font-semibold text-white">{title}</p>
{entry.vote_average > 0 && (
<span className="mt-0.5 flex items-center gap-1 text-xs text-yellow-400">
<Star className="h-3 w-3 fill-current" />
{entry.vote_average.toFixed(1)}
</span>
)}
</div>
</Link>
);
}
/* ─── Numbered List Item ────────────────────────────────────────────── */
function NumberedListItem({ entry, rank }: { entry: TmdbEntry; rank: number }) {
const title = entry.title || entry.name || 'Untitled';
const poster = entry.poster_path
? `https://image.tmdb.org/t/p/w92${entry.poster_path}`
: null;
const isTv = entry.media_type === 'tv' || !!entry.name;
const linkTo = `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${entry.id}`;
return (
<Link
to={linkTo}
className="group flex items-center gap-3 rounded-lg p-2 transition-colors hover:bg-accent/50"
>
<span className="w-8 text-center text-2xl font-black tabular-nums text-muted-foreground/40 transition-colors group-hover:text-foreground/60">
{rank}
</span>
<div className="h-12 w-8 shrink-0 overflow-hidden rounded bg-muted">
{poster && <img src={poster} alt="" className="h-full w-full object-cover" />}
</div>
<div className="min-w-0 flex-1">
<p className="truncate text-sm font-medium">{title}</p>
{entry.vote_average > 0 && (
<span className="flex items-center gap-1 text-xs text-muted-foreground">
<Star className="h-2.5 w-2.5 fill-yellow-400 text-yellow-400" />
{entry.vote_average.toFixed(1)}
</span>
)}
</div>
</Link>
);
}
/* ─── Mini Poster Card ──────────────────────────────────────────────── */
function MiniPosterCard({ entry, hideTitle }: { entry: TmdbEntry; hideTitle?: boolean }) {
const title = entry.title || entry.name || 'Untitled';
const poster = entry.poster_path
? `https://image.tmdb.org/t/p/w342${entry.poster_path}`
: null;
const isTv = entry.media_type === 'tv' || !!entry.name;
const linkTo = `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${entry.id}`;
return (
<Link to={linkTo} className="group space-y-2">
<div className="relative overflow-hidden rounded-lg bg-muted" style={{ aspectRatio: '2/3' }}>
{poster ? (
<img
src={poster}
alt={title}
className="h-full w-full object-cover transition-transform duration-300 group-hover:scale-105"
/>
) : (
<div className="flex h-full w-full items-center justify-center text-xs text-muted-foreground">
No Image
</div>
)}
</div>
{!hideTitle && <p className="truncate text-xs font-medium">{title}</p>}
</Link>
);
}
/* ─── Upcoming Card (small, for horizontal scroll) ──────────────────── */
function formatRelativeTime(dateStr: string): string {
const now = new Date();
const release = new Date(dateStr);
const diffMs = release.getTime() - now.getTime();
if (diffMs <= 0) return 'Out now';
const totalMinutes = Math.floor(diffMs / 60000);
const totalHours = Math.floor(totalMinutes / 60);
const totalDays = Math.floor(totalHours / 24);
const months = Math.floor(totalDays / 30);
const remDays = totalDays % 30;
if (months > 0 && remDays > 0) return `in ${months}m ${remDays}d`;
if (months > 0) return `in ${months}m`;
if (totalDays > 0) return `in ${totalDays} day${totalDays !== 1 ? 's' : ''}`;
if (totalHours > 0) return `in ${totalHours} hour${totalHours !== 1 ? 's' : ''}`;
if (totalMinutes > 0) return `in ${totalMinutes} min`;
return 'Very soon';
}
function UpcomingCard({ entry }: { entry: TmdbEntry }) {
const title = entry.title || entry.name || 'Untitled';
const poster = entry.poster_path
? `https://image.tmdb.org/t/p/w185${entry.poster_path}`
: null;
const isTv = entry.media_type === 'tv' || !!entry.name;
const linkTo = `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${entry.id}`;
const releaseDate = entry.release_date || entry.first_air_date;
const relativeTime = releaseDate ? formatRelativeTime(releaseDate) : null;
return (
<Link
to={linkTo}
className="group relative shrink-0 overflow-hidden rounded-xl border border-border/50 bg-card transition-colors hover:border-border"
style={{ width: '110px' }}
>
<div className="relative overflow-hidden" style={{ aspectRatio: '2/3' }}>
{poster ? (
<img
src={poster}
alt={title}
className="h-full w-full object-cover transition-transform duration-300 group-hover:scale-105"
/>
) : (
<div className="flex h-full w-full items-center justify-center bg-muted text-xs text-muted-foreground">
No Image
</div>
)}
{/* Date overlay — always visible at bottom of poster */}
{releaseDate && (
<div className="absolute bottom-0 left-0 right-0 bg-linear-to-t from-black/80 to-transparent px-2 py-2">
<p className="text-[9px] font-semibold leading-tight text-white/90">
{new Date(releaseDate).toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
})}
</p>
</div>
)}
{/* Hover overlay — shows relative countdown */}
{relativeTime && (
<div className="absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 backdrop-blur-[1px] transition-opacity duration-200 group-hover:opacity-100">
<span className="rounded-full bg-white/15 px-2.5 py-1 text-[10px] font-bold text-white backdrop-blur-sm">
{relativeTime}
</span>
</div>
)}
</div>
</Link>
);
}
/* ─── Section Header ────────────────────────────────────────────────── */
function SectionHeader({
icon,
title,
category,
}: {
icon: React.ReactNode;
title: string;
category: string;
}) {
return (
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
{icon}
<h2 className="text-xl font-bold">{title}</h2>
</div>
<Link
to={`/discover/${category}`}
className="text-sm text-muted-foreground transition-colors hover:text-foreground"
>
Explore All →
</Link>
</div>
);
}
/* ─── Loading Skeleton ──────────────────────────────────────────────── */
function LoadingSkeleton() {
return (
<div className="animate-pulse space-y-12 pb-12">
<div className="w-full rounded-2xl bg-muted" style={{ aspectRatio: '16/9', maxHeight: '70vh' }} />
<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>
);
}