- Replace old HomePage layout with Apple TV+/Hulu-inspired design (HomePage3) - Extract all home UI into reusable components under src/components/home/: HeroSlider, BackdropCard, BackdropScrollCard, PopularBelt, NumberedListItem, MiniPosterCard, UpcomingCard, SectionHeader - Hero slider: true slide-track animation, embedded search bar, autoplay with dot indicators - Trending Now: rotating 2x2 backdrop grid with slide-out/slide-in stagger animation (7s interval) - Popular Right Now: infinite CSS marquee belt, pauses on hover - Top Rated: 16:9 featured backdrop + 4 poster cards, no labels - Coming Soon: compact horizontal scroll, date overlay, relative countdown on hover - Fix sidebar ml offset in AppLayout (md:ml-56 -> md:ml-20) to re-center all pages - Move Collections page filters to top-right, search input to left
189 lines
7.3 KiB
TypeScript
189 lines
7.3 KiB
TypeScript
import { useState, useEffect, useRef } from 'react';
|
|
import { Link, useNavigate } from 'react-router-dom';
|
|
import { useCreateEntry } from '@/hooks/useEntries';
|
|
import { useLibraryStore } from '@/stores/useLibraryStore';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Star, Plus, Play, Search, ChevronLeft, ChevronRight } from 'lucide-react';
|
|
import type { TmdbEntry } from '@/types';
|
|
|
|
interface HeroSliderProps {
|
|
entries: TmdbEntry[];
|
|
}
|
|
|
|
export function HeroSlider({ entries }: HeroSliderProps) {
|
|
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 */}
|
|
<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 */}
|
|
<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 */}
|
|
<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 */}
|
|
<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>
|
|
);
|
|
}
|