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,31 +1,49 @@
|
||||
import { useState } from 'react';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { useState } from "react";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
import {
|
||||
Plus, Star, Loader2, Heart, EyeOff, Trash2, MoreHorizontal, X,
|
||||
Eye, History, FolderPlus, RefreshCw, ImageIcon, Settings,
|
||||
} from 'lucide-react';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
Plus,
|
||||
Star,
|
||||
Loader2,
|
||||
Heart,
|
||||
EyeOff,
|
||||
Trash2,
|
||||
MoreHorizontal,
|
||||
X,
|
||||
Eye,
|
||||
History,
|
||||
FolderPlus,
|
||||
RefreshCw,
|
||||
ImageIcon,
|
||||
Settings,
|
||||
} from "lucide-react";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { getPosterUrl, getYear, formatRuntime } from '@/lib/media-utils';
|
||||
import { useCreateEntry, useDeleteEntry, useUpdateEntry, useRefreshEntry, useEntrySeasons } from '@/hooks/useEntries';
|
||||
import { useEntrySeenByEntry, useDeleteEntrySeen } from '@/hooks/useEntrySeen';
|
||||
import { useLibraryStore } from '@/stores/useLibraryStore';
|
||||
import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog';
|
||||
import { EntrySeenDialog } from '@/components/dialogs/EntrySeenDialog';
|
||||
import { RatingDialog } from '@/components/dialogs/RatingDialog';
|
||||
import { MovieWatchHistoryDialog } from '@/components/dialogs/MovieWatchHistoryDialog';
|
||||
import { AddEntryToCollectionDialog } from '@/components/dialogs/AddEntryToCollectionDialog';
|
||||
import { EntryMediaDialog } from '@/components/dialogs/EntryMediaDialog';
|
||||
import { EntrySettingsDialog } from '@/components/dialogs/EntrySettingsDialog';
|
||||
import type { Entry, TmdbEntry } from '@/types';
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { getPosterUrl, getYear, formatRuntime } from "@/lib/media-utils";
|
||||
import {
|
||||
useCreateEntry,
|
||||
useDeleteEntry,
|
||||
useUpdateEntry,
|
||||
useRefreshEntry,
|
||||
useEntrySeasons,
|
||||
} from "@/hooks/useEntries";
|
||||
import { useEntrySeenByEntry, useDeleteEntrySeen } from "@/hooks/useEntrySeen";
|
||||
import { useLibraryStore } from "@/stores/useLibraryStore";
|
||||
import { ConfirmDialog } from "@/components/dialogs/ConfirmDialog";
|
||||
import { EntrySeenDialog } from "@/components/dialogs/EntrySeenDialog";
|
||||
import { RatingDialog } from "@/components/dialogs/RatingDialog";
|
||||
import { MovieWatchHistoryDialog } from "@/components/dialogs/MovieWatchHistoryDialog";
|
||||
import { AddEntryToCollectionDialog } from "@/components/dialogs/AddEntryToCollectionDialog";
|
||||
import { EntryMediaDialog } from "@/components/dialogs/EntryMediaDialog";
|
||||
import { EntrySettingsDialog } from "@/components/dialogs/EntrySettingsDialog";
|
||||
import type { Entry, TmdbEntry } from "@/types";
|
||||
|
||||
interface EntryCardProps {
|
||||
entry?: Entry;
|
||||
@@ -37,15 +55,23 @@ interface EntryCardProps {
|
||||
onRemoveFromCollection?: (entryId: number) => void;
|
||||
}
|
||||
|
||||
export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRemoveFromCollection }: EntryCardProps) {
|
||||
export function EntryCard({
|
||||
entry,
|
||||
tmdbEntry,
|
||||
showTypeBadge,
|
||||
collectionId,
|
||||
onRemoveFromCollection,
|
||||
}: EntryCardProps) {
|
||||
const [showConfirm, setShowConfirm] = useState(false);
|
||||
const [showRemoveCollectionConfirm, setShowRemoveCollectionConfirm] = useState(false);
|
||||
const [showRemoveCollectionConfirm, setShowRemoveCollectionConfirm] =
|
||||
useState(false);
|
||||
const [showSeenDialog, setShowSeenDialog] = useState(false);
|
||||
const [showRatingDialog, setShowRatingDialog] = useState(false);
|
||||
const [showWatchHistoryDialog, setShowWatchHistoryDialog] = useState(false);
|
||||
const [showCollectionDialog, setShowCollectionDialog] = useState(false);
|
||||
const [showMediaDialog, setShowMediaDialog] = useState(false);
|
||||
const [showSettingsDialog, setShowSettingsDialog] = useState(false);
|
||||
const [dropdownOpen, setDropdownOpen] = useState(false);
|
||||
const navigate = useNavigate();
|
||||
const createEntry = useCreateEntry();
|
||||
const deleteEntry = useDeleteEntry();
|
||||
@@ -66,7 +92,7 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRem
|
||||
|
||||
// Resolve display data
|
||||
const title =
|
||||
displayEntry?.title || tmdbEntry?.title || tmdbEntry?.name || 'Untitled';
|
||||
displayEntry?.title || tmdbEntry?.title || tmdbEntry?.name || "Untitled";
|
||||
const year = displayEntry
|
||||
? getYear(displayEntry.release_date)
|
||||
: getYear(tmdbEntry?.release_date || tmdbEntry?.first_air_date || null);
|
||||
@@ -77,22 +103,22 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRem
|
||||
const runtime =
|
||||
displayEntry && !displayEntry.is_tvseries
|
||||
? formatRuntime(displayEntry.runtime)
|
||||
: '';
|
||||
: "";
|
||||
const isTv =
|
||||
displayEntry?.is_tvseries ||
|
||||
tmdbEntry?.media_type === 'tv' ||
|
||||
tmdbEntry?.media_type === "tv" ||
|
||||
!!tmdbEntry?.name;
|
||||
|
||||
const posterUrl = displayEntry
|
||||
? getPosterUrl(displayEntry)
|
||||
: tmdbEntry?.poster_path
|
||||
? `https://image.tmdb.org/t/p/w342${tmdbEntry.poster_path}`
|
||||
: '/images/default-poster.png';
|
||||
: "/images/default-poster.png";
|
||||
|
||||
const entryLink = displayEntry
|
||||
? `/entry/${displayEntry.id}`
|
||||
: tmdbEntry
|
||||
? `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${tmdbEntry.id}`
|
||||
? `/entry/tmdb/${isTv ? "tv" : "movie"}/${tmdbEntry.id}`
|
||||
: undefined;
|
||||
|
||||
const handleAdd = (e: React.MouseEvent) => {
|
||||
@@ -101,7 +127,7 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRem
|
||||
if (!tmdbEntry) return;
|
||||
createEntry.mutate(
|
||||
{ tmdb_id: tmdbEntry.id, is_tvserie: isTv },
|
||||
{ onSuccess: (newEntry) => navigate(`/entry/${newEntry.id}`) }
|
||||
{ onSuccess: (newEntry) => navigate(`/entry/${newEntry.id}`) },
|
||||
);
|
||||
};
|
||||
|
||||
@@ -115,13 +141,19 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRem
|
||||
|
||||
const toggleFavorite = () => {
|
||||
if (libraryEntry) {
|
||||
updateEntry.mutate({ id: libraryEntry.id, data: { favorit: !libraryEntry.favorit } });
|
||||
updateEntry.mutate({
|
||||
id: libraryEntry.id,
|
||||
data: { favorit: !libraryEntry.favorit },
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const toggleHidden = () => {
|
||||
if (libraryEntry) {
|
||||
updateEntry.mutate({ id: libraryEntry.id, data: { hidden: !libraryEntry.hidden } });
|
||||
updateEntry.mutate({
|
||||
id: libraryEntry.id,
|
||||
data: { hidden: !libraryEntry.hidden },
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -150,62 +182,116 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRem
|
||||
|
||||
{/* Quick actions button – top right, shown on hover */}
|
||||
{isInLibrary && (
|
||||
<div className="absolute right-2 top-2 z-20 opacity-0 transition-opacity group-hover:opacity-100">
|
||||
<DropdownMenu>
|
||||
<div className={`absolute right-2 top-2 z-20 transition-opacity ${dropdownOpen ? 'opacity-100' : 'opacity-0 group-hover:opacity-100'}`}>
|
||||
<DropdownMenu open={dropdownOpen} onOpenChange={setDropdownOpen}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={(e) => { e.preventDefault(); e.stopPropagation(); }}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}}
|
||||
>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-52" onClick={(e) => e.stopPropagation()}>
|
||||
<DropdownMenuContent
|
||||
align="end"
|
||||
className="w-52"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* Watch & Rate */}
|
||||
<DropdownMenuItem onClick={(e) => { e.stopPropagation(); setShowSeenDialog(true); }}>
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setShowSeenDialog(true);
|
||||
}}
|
||||
>
|
||||
<Eye className="mr-2 h-4 w-4" />
|
||||
Mark as watched
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={(e) => { e.stopPropagation(); setShowRatingDialog(true); }}>
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setShowRatingDialog(true);
|
||||
}}
|
||||
>
|
||||
<Star className="mr-2 h-4 w-4" />
|
||||
Rate this
|
||||
</DropdownMenuItem>
|
||||
{!isTv && (
|
||||
<DropdownMenuItem onClick={(e) => { e.stopPropagation(); setShowWatchHistoryDialog(true); }}>
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setShowWatchHistoryDialog(true);
|
||||
}}
|
||||
>
|
||||
<History className="mr-2 h-4 w-4" />
|
||||
Watch History
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuSeparator />
|
||||
{/* Organize */}
|
||||
<DropdownMenuItem onClick={(e) => { e.stopPropagation(); toggleFavorite(); }}>
|
||||
<Heart className={`mr-2 h-4 w-4 ${libraryEntry?.favorit ? 'fill-current' : ''}`} />
|
||||
{libraryEntry?.favorit ? 'Unfavorite' : 'Favorite'}
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
toggleFavorite();
|
||||
}}
|
||||
>
|
||||
<Heart
|
||||
className={`mr-2 h-4 w-4 ${libraryEntry?.favorit ? "fill-current" : ""}`}
|
||||
/>
|
||||
{libraryEntry?.favorit ? "Unfavorite" : "Favorite"}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={(e) => { e.stopPropagation(); setShowCollectionDialog(true); }}>
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setShowCollectionDialog(true);
|
||||
}}
|
||||
>
|
||||
<FolderPlus className="mr-2 h-4 w-4" />
|
||||
Add to collection
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={(e) => { e.stopPropagation(); toggleHidden(); }}>
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
toggleHidden();
|
||||
}}
|
||||
>
|
||||
<EyeOff className="mr-2 h-4 w-4" />
|
||||
{libraryEntry?.hidden ? 'Unhide' : 'Hide'}
|
||||
{libraryEntry?.hidden ? "Unhide" : "Hide"}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
{/* Manage */}
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => { e.stopPropagation(); refreshEntry.mutate(libraryEntry!.id); }}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
refreshEntry.mutate(libraryEntry!.id);
|
||||
}}
|
||||
disabled={refreshEntry.isPending}
|
||||
>
|
||||
<RefreshCw className={`mr-2 h-4 w-4 ${refreshEntry.isPending ? 'animate-spin' : ''}`} />
|
||||
{refreshEntry.isPending ? 'Refreshing...' : 'Refresh details'}
|
||||
<RefreshCw
|
||||
className={`mr-2 h-4 w-4 ${refreshEntry.isPending ? "animate-spin" : ""}`}
|
||||
/>
|
||||
{refreshEntry.isPending ? "Refreshing..." : "Refresh details"}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={(e) => { e.stopPropagation(); setShowMediaDialog(true); }}>
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setShowMediaDialog(true);
|
||||
}}
|
||||
>
|
||||
<ImageIcon className="mr-2 h-4 w-4" />
|
||||
Manage media
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={(e) => { e.stopPropagation(); setShowSettingsDialog(true); }}>
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setShowSettingsDialog(true);
|
||||
}}
|
||||
>
|
||||
<Settings className="mr-2 h-4 w-4" />
|
||||
Settings
|
||||
</DropdownMenuItem>
|
||||
@@ -214,7 +300,10 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRem
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => { e.stopPropagation(); setShowRemoveCollectionConfirm(true); }}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setShowRemoveCollectionConfirm(true);
|
||||
}}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
<X className="mr-2 h-4 w-4" />
|
||||
@@ -225,7 +314,10 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRem
|
||||
<DropdownMenuSeparator />
|
||||
{/* Danger */}
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => { e.stopPropagation(); setShowConfirm(true); }}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setShowConfirm(true);
|
||||
}}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
<Trash2 className="mr-2 h-4 w-4" />
|
||||
@@ -242,7 +334,7 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRem
|
||||
variant="secondary"
|
||||
className="absolute bottom-2 right-2 text-[10px] px-1.5 py-0.5 opacity-90 z-10 pointer-events-none"
|
||||
>
|
||||
{isTv ? 'TV Series' : 'Movie'}
|
||||
{isTv ? "TV Series" : "Movie"}
|
||||
</Badge>
|
||||
)}
|
||||
|
||||
@@ -256,7 +348,7 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRem
|
||||
{rating != null && rating > 0 && (
|
||||
<span className="flex items-center gap-1">
|
||||
<Star className="h-3 w-3 fill-yellow-400 text-yellow-400" />
|
||||
{typeof rating === 'number' ? rating.toFixed(1) : rating}
|
||||
{typeof rating === "number" ? rating.toFixed(1) : rating}
|
||||
</span>
|
||||
)}
|
||||
{year && <span>{year}</span>}
|
||||
@@ -277,7 +369,7 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRem
|
||||
) : (
|
||||
<Plus className="mr-1 h-3 w-3" />
|
||||
)}
|
||||
{createEntry.isPending ? 'Adding...' : 'Add to Library'}
|
||||
{createEntry.isPending ? "Adding..." : "Add to Library"}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
@@ -286,19 +378,10 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRem
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
{entryLink ? (
|
||||
<Link to={entryLink}>{card}</Link>
|
||||
) : (
|
||||
card
|
||||
)}
|
||||
{entryLink ? <Link to={entryLink}>{card}</Link> : card}
|
||||
<ConfirmDialog
|
||||
open={showConfirm}
|
||||
onOpenChange={setShowConfirm}
|
||||
@@ -371,7 +454,11 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRem
|
||||
|
||||
/* Lazy wrappers – only mount when dialog is open so hooks fetch on demand */
|
||||
|
||||
function LazyEntrySeenDialog({ entry, open, onOpenChange }: {
|
||||
function LazyEntrySeenDialog({
|
||||
entry,
|
||||
open,
|
||||
onOpenChange,
|
||||
}: {
|
||||
entry: Entry;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
@@ -388,7 +475,11 @@ function LazyEntrySeenDialog({ entry, open, onOpenChange }: {
|
||||
);
|
||||
}
|
||||
|
||||
function LazyMovieWatchHistoryDialog({ entryId, open, onOpenChange }: {
|
||||
function LazyMovieWatchHistoryDialog({
|
||||
entryId,
|
||||
open,
|
||||
onOpenChange,
|
||||
}: {
|
||||
entryId: number;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState, useMemo, useCallback, useEffect, useRef } from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { useSearchParams, useNavigationType } from 'react-router-dom';
|
||||
import { useLibrary } from '@/hooks/useEntries';
|
||||
import { useLibraryEntries } from '@/stores/useLibraryStore';
|
||||
import { useLibraryFiltersStore, defaultFilters } from '@/stores/useLibraryFiltersStore';
|
||||
@@ -52,6 +52,7 @@ const PAGE_SIZE = 28;
|
||||
export function LibraryPage() {
|
||||
const { isLoading } = useLibrary();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const navigationType = useNavigationType();
|
||||
|
||||
// Persistent filter state from store
|
||||
const activeTab = useLibraryFiltersStore((s) => s.activeTab);
|
||||
@@ -65,6 +66,7 @@ export function LibraryPage() {
|
||||
const filters = useLibraryFiltersStore((s) => s.filters);
|
||||
const setFilters = useLibraryFiltersStore((s) => s.setFilters);
|
||||
const clearFilters = useLibraryFiltersStore((s) => s.clearFilters);
|
||||
const resetAll = useLibraryFiltersStore((s) => s.resetAll);
|
||||
|
||||
const [debouncedSearch, setDebouncedSearch] = useState(search);
|
||||
const [debouncedFilters, setDebouncedFilters] = useState<Filters>(filters);
|
||||
@@ -73,6 +75,15 @@ export function LibraryPage() {
|
||||
|
||||
const allEntries = useLibraryEntries();
|
||||
|
||||
// Reset filters when navigating TO the library (not when pressing back)
|
||||
useEffect(() => {
|
||||
if (navigationType !== 'POP') {
|
||||
resetAll();
|
||||
}
|
||||
// Only run on mount
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
// Read URL query params once on mount
|
||||
useEffect(() => {
|
||||
if (filtersInitialized.current) return;
|
||||
|
||||
@@ -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` }}
|
||||
>
|
||||
|
||||
@@ -4,9 +4,11 @@ import { useLibraryStore } from '@/stores/useLibraryStore';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { Star, Plus, Loader2, ExternalLink, Tv, Film } from 'lucide-react';
|
||||
import { Star, Plus, Loader2, ExternalLink } from 'lucide-react';
|
||||
import { EntryDetailsSkeleton } from '@/components/skeletons/PageSkeletons';
|
||||
import { CastList } from "@/components/entries/CastList";
|
||||
import { getYear, formatRuntime } from '@/lib/media-utils';
|
||||
import type { Credit } from '@/types';
|
||||
|
||||
const TMDB_IMG = 'https://image.tmdb.org/t/p';
|
||||
|
||||
@@ -127,25 +129,13 @@ export function TmdbPreviewPage() {
|
||||
{/* RIGHT: Info */}
|
||||
<div className="flex-1 min-w-0 space-y-4">
|
||||
{/* Title */}
|
||||
<div className="space-y-1">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold leading-tight">{preview.title}</h1>
|
||||
{preview.tagline && (
|
||||
<p className="text-sm text-muted-foreground italic">{preview.tagline}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Meta */}
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm text-muted-foreground">
|
||||
<span className="inline-flex items-center gap-1">
|
||||
{preview.is_tvseries ? <Tv className="h-3.5 w-3.5" /> : <Film className="h-3.5 w-3.5" />}
|
||||
{preview.is_tvseries ? 'TV Series' : 'Movie'}
|
||||
</span>
|
||||
{preview.release_date && (
|
||||
<>
|
||||
<span>•</span>
|
||||
<span>{getYear(preview.release_date)}</span>
|
||||
</>
|
||||
)}
|
||||
{preview.release_date && <span>{getYear(preview.release_date)}</span>}
|
||||
{preview.is_tvseries && preview.status && (
|
||||
<>
|
||||
<span>•</span>
|
||||
@@ -154,7 +144,7 @@ export function TmdbPreviewPage() {
|
||||
)}
|
||||
{preview.runtime && !preview.is_tvseries && (
|
||||
<>
|
||||
<span>•</span>
|
||||
{preview.release_date && <span>•</span>}
|
||||
<span>{formatRuntime(preview.runtime)}</span>
|
||||
</>
|
||||
)}
|
||||
@@ -207,6 +197,16 @@ export function TmdbPreviewPage() {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sections */}
|
||||
<div className="mt-10 space-y-8">
|
||||
{preview.credits && preview.credits.length > 0 && (
|
||||
<>
|
||||
<Separator />
|
||||
<CastList credits={preview.credits as unknown as Credit[]} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -27,6 +27,7 @@ interface LibraryFiltersState {
|
||||
setSortDir: (dir: SortDir) => void;
|
||||
setFilters: (updater: Filters | ((prev: Filters) => Filters)) => void;
|
||||
clearFilters: () => void;
|
||||
resetAll: () => void;
|
||||
}
|
||||
|
||||
const defaultFilters: Filters = {
|
||||
@@ -55,6 +56,14 @@ export const useLibraryFiltersStore = create<LibraryFiltersState>((set) => ({
|
||||
filters: typeof updater === 'function' ? updater(state.filters) : updater,
|
||||
})),
|
||||
clearFilters: () => set({ filters: defaultFilters }),
|
||||
resetAll: () =>
|
||||
set({
|
||||
activeTab: 'all',
|
||||
search: '',
|
||||
sortField: 'date_last_seen',
|
||||
sortDir: 'desc',
|
||||
filters: defaultFilters,
|
||||
}),
|
||||
}));
|
||||
|
||||
export { defaultFilters };
|
||||
|
||||
@@ -245,6 +245,19 @@ export interface TmdbPaginatedResponse<T> {
|
||||
total_results: number;
|
||||
}
|
||||
|
||||
export interface TmdbPreviewCredit {
|
||||
id: string | number;
|
||||
cast_type: 'cast';
|
||||
character: string | null;
|
||||
people_id: number;
|
||||
people: {
|
||||
id: number;
|
||||
name: string;
|
||||
profile_path: string | null;
|
||||
tmdb_id: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface TmdbPreview {
|
||||
tmdb_id: number;
|
||||
title: string;
|
||||
@@ -265,4 +278,5 @@ export interface TmdbPreview {
|
||||
networks: { id: number; name: string; logo_path: string | null }[];
|
||||
homepage: string | null;
|
||||
imdb_id: string | null;
|
||||
credits: TmdbPreviewCredit[];
|
||||
}
|
||||
Reference in new issue
Block a user