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
@@ -1,8 +1,8 @@
|
||||
import { useState, useMemo } from 'react';
|
||||
import { useState, useMemo, useEffect } from 'react';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { useCollection, useDeleteCollection, useGetCollectionParts, useRemoveEntryFromCollection } from '@/hooks/useCollections';
|
||||
import { EntryLibraryGrid } from '@/components/entries/EntryLibraryGrid';
|
||||
import { getCollectionPosterUrl } from '@/lib/media-utils';
|
||||
import { getCollectionPosterUrl, getBackdropUrl } from '@/lib/media-utils';
|
||||
import { getTmdbImageUrl } from '@/lib/api';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { Star, MoreVertical, Pencil, Download, Trash2, ArrowUpDown, ArrowUp, ArrowDown } from 'lucide-react';
|
||||
import { Star, MoreVertical, Pencil, Download, Trash2, ArrowUp, ArrowDown } from 'lucide-react';
|
||||
import { CollectionEditDialog } from '@/components/dialogs/CollectionEditDialog';
|
||||
import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog';
|
||||
import { toast } from 'sonner';
|
||||
@@ -33,37 +33,13 @@ export function CollectionDetailsPage() {
|
||||
const getCollectionParts = useGetCollectionParts();
|
||||
const removeEntryFromCollection = useRemoveEntryFromCollection();
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Skeleton className="h-48 w-full rounded-xl" />
|
||||
<Skeleton className="h-8 w-64" />
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="aspect-2/3 w-full rounded-lg" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!collection || isError) {
|
||||
toast.error('Collection not found');
|
||||
navigate('/collections', { replace: true });
|
||||
return null;
|
||||
}
|
||||
|
||||
const backdropUrl = collection.backdrop_path
|
||||
? getTmdbImageUrl(collection.backdrop_path, 'w1280')
|
||||
: null;
|
||||
|
||||
const entries = (collection.entries || []).map((e) => ({
|
||||
...e,
|
||||
isInLibrary: true,
|
||||
}));
|
||||
const entries = useMemo(
|
||||
() => (collection?.entries || []).map((e) => ({ ...e, isInLibrary: true })),
|
||||
[collection?.entries]
|
||||
);
|
||||
|
||||
const sortedEntries = useMemo(() => {
|
||||
const sorted = [...entries].sort((a, b) => {
|
||||
return [...entries].sort((a, b) => {
|
||||
let cmp = 0;
|
||||
switch (sortField) {
|
||||
case 'order': {
|
||||
@@ -90,9 +66,22 @@ export function CollectionDetailsPage() {
|
||||
}
|
||||
return sortDir === 'asc' ? cmp : -cmp;
|
||||
});
|
||||
return sorted;
|
||||
}, [entries, sortField, sortDir]);
|
||||
|
||||
// Fallback backdrop: use first entry's backdrop if collection has none
|
||||
const backdropUrl = useMemo(() => {
|
||||
if (collection?.backdrop_path) return getTmdbImageUrl(collection.backdrop_path, 'w1280');
|
||||
// Try to find a backdrop from one of the entries
|
||||
const entryWithBackdrop = entries.find((e) => e.banner_path);
|
||||
if (entryWithBackdrop?.banner_path) return getTmdbImageUrl(entryWithBackdrop.banner_path, 'w1280');
|
||||
// Try entry medias
|
||||
for (const e of entries) {
|
||||
const url = getBackdropUrl(e);
|
||||
if (url) return url;
|
||||
}
|
||||
return null;
|
||||
}, [collection?.backdrop_path, entries]);
|
||||
|
||||
const handleSort = (field: CollectionSortField) => {
|
||||
if (field === sortField) {
|
||||
setSortDir((d) => (d === 'asc' ? 'desc' : 'asc'));
|
||||
@@ -102,6 +91,30 @@ export function CollectionDetailsPage() {
|
||||
}
|
||||
};
|
||||
|
||||
// Handle error redirect in useEffect (not during render)
|
||||
useEffect(() => {
|
||||
if (!isLoading && (isError || (!collection && !isLoading))) {
|
||||
toast.error('Collection not found');
|
||||
navigate('/collections', { replace: true });
|
||||
}
|
||||
}, [isLoading, isError, collection, navigate]);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Skeleton className="h-48 w-full rounded-xl" />
|
||||
<Skeleton className="h-8 w-64" />
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="aspect-2/3 w-full rounded-lg" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!collection) return null;
|
||||
|
||||
const handleDelete = () => {
|
||||
deleteCollection.mutate(collection.id, {
|
||||
onSuccess: () => navigate('/collections', { replace: true }),
|
||||
@@ -123,7 +136,7 @@ export function CollectionDetailsPage() {
|
||||
className="h-48 w-full object-cover sm:h-64"
|
||||
/>
|
||||
) : (
|
||||
<div className="h-48 w-full bg-muted sm:h-64" />
|
||||
<div className="h-48 w-full bg-linear-to-br from-primary/15 to-primary/5 sm:h-64" />
|
||||
)}
|
||||
<div className="absolute inset-0 bg-linear-to-t from-background via-background/60 to-transparent" />
|
||||
|
||||
@@ -186,32 +199,31 @@ export function CollectionDetailsPage() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sort – bottom right */}
|
||||
{entries.length > 1 && (
|
||||
<div className="ml-auto flex items-center gap-1 self-end">
|
||||
{(['order', 'year', 'title', 'rating'] as const).map((field) => (
|
||||
<Button
|
||||
key={field}
|
||||
variant={sortField === field ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
className="h-7 text-xs capitalize gap-1"
|
||||
onClick={() => handleSort(field)}
|
||||
>
|
||||
{field}
|
||||
{sortField === field && (
|
||||
sortDir === 'asc'
|
||||
? <ArrowUp className="h-3 w-3" />
|
||||
: <ArrowDown className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sort toolbar */}
|
||||
{entries.length > 1 && (
|
||||
<div className="flex items-center gap-1.5">
|
||||
<ArrowUpDown className="h-4 w-4 text-muted-foreground shrink-0" />
|
||||
{(['order', 'year', 'title', 'rating'] as const).map((field) => (
|
||||
<Button
|
||||
key={field}
|
||||
variant={sortField === field ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
className="h-7 text-xs capitalize gap-1"
|
||||
onClick={() => handleSort(field)}
|
||||
>
|
||||
{field}
|
||||
{sortField === field && (
|
||||
sortDir === 'asc'
|
||||
? <ArrowUp className="h-3 w-3" />
|
||||
: <ArrowDown className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Entries grid */}
|
||||
<EntryLibraryGrid
|
||||
entries={sortedEntries}
|
||||
|
||||
Reference in new issue
Block a user