Implemented the new react version of the frontend

This commit is contained in:
Mohammed Abad committed 2026-03-31 01:56:38 +01:00
1 parent 236e6e06fb
commit ffe7e52527
65 files changed
+5228 -177

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
import { useState, useCallback, useRef, useEffect } from 'react';
import { Link } from 'react-router-dom';
import { usePopularPeople, useTmdbSearchPeople } from '@/hooks/useTmdb';
import { Input } from '@/components/ui/input';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Skeleton } from '@/components/ui/skeleton';
import { Search } from 'lucide-react';
import { getProfileUrl } from '@/lib/media-utils';
export function PeoplePage() {
const [search, setSearch] = useState('');
const isSearching = search.length > 0;
const popularQuery = usePopularPeople();
const searchQuery = useTmdbSearchPeople(search);
const activeQuery = isSearching ? searchQuery : popularQuery;
const people = activeQuery.data?.pages.flatMap((p) => p.results) ?? [];
const observerRef = useRef<IntersectionObserver | null>(null);
const lastRef = useCallback(
(node: HTMLDivElement | null) => {
if (activeQuery.isFetchingNextPage) return;
if (observerRef.current) observerRef.current.disconnect();
observerRef.current = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting && activeQuery.hasNextPage) {
activeQuery.fetchNextPage();
}
});
if (node) observerRef.current.observe(node);
},
[activeQuery.isFetchingNextPage, activeQuery.hasNextPage, activeQuery.fetchNextPage]
);
useEffect(() => {
return () => observerRef.current?.disconnect();
}, []);
return (
<div className="space-y-6">
<h1 className="text-2xl font-bold">People</h1>
<div className="relative max-w-xs">
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
<Input
placeholder="Search people..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="pl-10"
/>
</div>
{activeQuery.isLoading ? (
<div className="grid grid-cols-3 gap-4 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 xl:grid-cols-8">
{Array.from({ length: 24 }).map((_, i) => (
<div key={i} className="flex flex-col items-center gap-2">
<Skeleton className="h-24 w-24 rounded-full" />
<Skeleton className="h-4 w-20" />
</div>
))}
</div>
) : (
<div className="grid grid-cols-3 gap-4 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 xl:grid-cols-8">
{people.map((person, index) => (
<div
key={person.id}
ref={index === people.length - 1 ? lastRef : undefined}
>
<Link
to={`/people/${person.id}`}
className="group flex flex-col items-center gap-2 text-center"
>
<Avatar className="h-24 w-24 transition-transform group-hover:scale-105">
<AvatarImage
src={getProfileUrl(person.profile_path)}
alt={person.name}
/>
<AvatarFallback>
{person.name
.split(' ')
.map((n) => n[0])
.join('')}
</AvatarFallback>
</Avatar>
<p className="text-sm font-medium line-clamp-2">
{person.name}
</p>
</Link>
</div>
))}
</div>
)}
</div>
);
}