feat(frontend): fix hooks crash, persist library filters, improve UI
- Fix "rendered more hooks" crash in CollectionDetailsPage by moving all hooks before conditionals - Persist library search/filters only on back navigation using useNavigationType - Add resetAll() to useLibraryFiltersStore - Move sort toolbar to hero bottom-right in CollectionDetailsPage - Fall back to entry backdrops when collection has none - Show full cast in TmdbPreviewPage matching EntryDetailsPage layout - Remove tagline/icons from TmdbPreviewPage to match in-library style - Lazy load people in local DB mode with infinite scroll - Move All/Favorite filter to right side in PeoplePage, always visible - Track dropdownOpen state in EntryCard to fix menu close flash Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
1 parent
ea143fb32a
commit
a42d4ee7d7
7 files changed
+325
-177
No files matched your search
@@ -5,19 +5,21 @@ import { useSearchLocalPeople } from '@/hooks/usePeople';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { Search, Heart } from 'lucide-react';
|
||||
import { getProfileUrl } from '@/lib/media-utils';
|
||||
|
||||
type PeopleFilter = 'all' | 'favorite';
|
||||
const LOCAL_PAGE_SIZE = 48;
|
||||
|
||||
export function PeoplePage() {
|
||||
const [search, setSearch] = useState('');
|
||||
const [debouncedSearch, setDebouncedSearch] = useState('');
|
||||
const [filter, setFilter] = useState<PeopleFilter>('all');
|
||||
const [localOnly, setLocalOnly] = useState(false);
|
||||
const [localVisibleCount, setLocalVisibleCount] = useState(LOCAL_PAGE_SIZE);
|
||||
|
||||
// Debounce search input
|
||||
useEffect(() => {
|
||||
@@ -25,6 +27,11 @@ export function PeoplePage() {
|
||||
return () => clearTimeout(timer);
|
||||
}, [search]);
|
||||
|
||||
// Reset visible count when filter/search changes
|
||||
useEffect(() => {
|
||||
setLocalVisibleCount(LOCAL_PAGE_SIZE);
|
||||
}, [debouncedSearch, filter, localOnly]);
|
||||
|
||||
const isSearching = debouncedSearch.length > 0;
|
||||
|
||||
const popularQuery = usePopularPeople();
|
||||
@@ -43,31 +50,40 @@ export function PeoplePage() {
|
||||
);
|
||||
|
||||
// Determine displayed people
|
||||
const filteredLocalPeople = useMemo(() => {
|
||||
if (!localOnly) return [];
|
||||
const people = isSearching ? localSearchResults : allLocalPeople;
|
||||
if (filter === 'favorite') {
|
||||
return people.filter((p: any) => p.favorite);
|
||||
}
|
||||
return people;
|
||||
}, [localOnly, isSearching, localSearchResults, allLocalPeople, filter]);
|
||||
|
||||
const displayPeople = useMemo(() => {
|
||||
if (localOnly) {
|
||||
const people = isSearching ? localSearchResults : allLocalPeople;
|
||||
if (filter === 'favorite') {
|
||||
return people.filter((p: any) => p.favorite);
|
||||
}
|
||||
return people;
|
||||
return filteredLocalPeople.slice(0, localVisibleCount);
|
||||
}
|
||||
// TMDB mode - filter not applicable for TMDB results
|
||||
return tmdbPeople;
|
||||
}, [localOnly, isSearching, localSearchResults, allLocalPeople, tmdbPeople, filter]);
|
||||
}, [localOnly, filteredLocalPeople, localVisibleCount, tmdbPeople]);
|
||||
|
||||
const hasMoreLocal = localOnly && localVisibleCount < filteredLocalPeople.length;
|
||||
|
||||
const observerRef = useRef<IntersectionObserver | null>(null);
|
||||
const lastRef = useCallback(
|
||||
(node: HTMLDivElement | null) => {
|
||||
if (!activeQuery || activeQuery.isFetchingNextPage) return;
|
||||
if (observerRef.current) observerRef.current.disconnect();
|
||||
if (!node) return;
|
||||
observerRef.current = new IntersectionObserver((entries) => {
|
||||
if (entries[0].isIntersecting && activeQuery.hasNextPage) {
|
||||
if (!entries[0].isIntersecting) return;
|
||||
if (localOnly) {
|
||||
if (hasMoreLocal) setLocalVisibleCount((c) => c + LOCAL_PAGE_SIZE);
|
||||
} else if (activeQuery && !activeQuery.isFetchingNextPage && activeQuery.hasNextPage) {
|
||||
activeQuery.fetchNextPage();
|
||||
}
|
||||
});
|
||||
if (node) observerRef.current.observe(node);
|
||||
observerRef.current.observe(node);
|
||||
},
|
||||
[activeQuery?.isFetchingNextPage, activeQuery?.hasNextPage, activeQuery?.fetchNextPage]
|
||||
[localOnly, hasMoreLocal, activeQuery?.isFetchingNextPage, activeQuery?.hasNextPage, activeQuery?.fetchNextPage]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -94,31 +110,8 @@ export function PeoplePage() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Filter: All / Favorite (only in local mode) */}
|
||||
{localOnly && (
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant={filter === 'all' ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
className="h-8 text-xs"
|
||||
onClick={() => setFilter('all')}
|
||||
>
|
||||
All
|
||||
</Button>
|
||||
<Button
|
||||
variant={filter === 'favorite' ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
className="h-8 text-xs gap-1"
|
||||
onClick={() => setFilter('favorite')}
|
||||
>
|
||||
<Heart className="h-3 w-3" />
|
||||
Favorite
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Local DB toggle */}
|
||||
<div className="flex items-center gap-2 ml-auto">
|
||||
<div className="flex items-center gap-2">
|
||||
<Switch
|
||||
id="local-toggle"
|
||||
checked={localOnly}
|
||||
@@ -128,6 +121,24 @@ export function PeoplePage() {
|
||||
Local DB
|
||||
</Label>
|
||||
</div>
|
||||
|
||||
{/* Filter tabs: All / Favorite — always visible, disabled when not local */}
|
||||
<div className="ml-auto">
|
||||
<Tabs
|
||||
value={filter}
|
||||
onValueChange={(v) => setFilter(v as PeopleFilter)}
|
||||
>
|
||||
<TabsList>
|
||||
<TabsTrigger value="all" disabled={!localOnly}>
|
||||
All
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="favorite" disabled={!localOnly}>
|
||||
<Heart className="mr-1 h-3 w-3" />
|
||||
Favorite
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
@@ -148,7 +159,7 @@ export function PeoplePage() {
|
||||
{displayPeople.map((person: any, index: number) => (
|
||||
<div
|
||||
key={person.id}
|
||||
ref={!localOnly && index === displayPeople.length - 1 ? lastRef : undefined}
|
||||
ref={index === displayPeople.length - 1 ? lastRef : undefined}
|
||||
className="animate-card-enter"
|
||||
style={{ animationDelay: `${Math.min(index * 20, 300)}ms` }}
|
||||
>
|
||||
|
||||
Reference in new issue
Block a user