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;
|
||||
|
||||
Reference in new issue
Block a user