feat(frontend): navigate non-library entries to TMDB preview page
- Add TmdbPreviewPage showing TMDB details without adding to library - Display backdrop, poster, title, tagline, genres, rating, storyline - Show season/episode count for TV series - Add "Add to Library" button that creates entry then redirects to details page - Show "Already in Library — View" if entry exists in DB - Add /entry/tmdb/:type/:tmdbId route in router.tsx - Add TmdbPreview type, entriesApi.previewTmdb(), and useTmdbPreview() hook - Update EntryCard to navigate to preview page instead of auto-adding Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
1 parent
25b645a16f
commit
02cdcf733d
18 files changed
+949
-204
No files matched your search
@@ -1,32 +1,56 @@
|
||||
import { useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Plus, Trash2, Star, Loader2, Calendar, Clock } from 'lucide-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';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { getPosterUrl, getYear, formatRuntime } from '@/lib/media-utils';
|
||||
import { useCreateEntry, useDeleteEntry } from '@/hooks/useEntries';
|
||||
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;
|
||||
tmdbEntry?: TmdbEntry;
|
||||
showTypeBadge?: boolean;
|
||||
/** When inside a collection, provide the collection ID to show "Remove from collection" action */
|
||||
collectionId?: number;
|
||||
/** Callback to remove entry from collection */
|
||||
onRemoveFromCollection?: (entryId: number) => void;
|
||||
}
|
||||
|
||||
export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) {
|
||||
export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRemoveFromCollection }: EntryCardProps) {
|
||||
const [showConfirm, setShowConfirm] = useState(false);
|
||||
const [showDetailDialog, setShowDetailDialog] = 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 navigate = useNavigate();
|
||||
const createEntry = useCreateEntry();
|
||||
const deleteEntry = useDeleteEntry();
|
||||
const updateEntry = useUpdateEntry();
|
||||
const refreshEntry = useRefreshEntry();
|
||||
const libraryEntry = useLibraryStore((s) => {
|
||||
if (entry?.isInLibrary) return entry;
|
||||
if (tmdbEntry) {
|
||||
@@ -67,19 +91,18 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) {
|
||||
|
||||
const entryLink = displayEntry
|
||||
? `/entry/${displayEntry.id}`
|
||||
: undefined;
|
||||
: tmdbEntry
|
||||
? `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${tmdbEntry.id}`
|
||||
: undefined;
|
||||
|
||||
const handleAdd = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (!tmdbEntry) return;
|
||||
createEntry.mutate({ tmdb_id: tmdbEntry.id, is_tvserie: isTv });
|
||||
};
|
||||
|
||||
const handleRemove = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setShowConfirm(true);
|
||||
createEntry.mutate(
|
||||
{ tmdb_id: tmdbEntry.id, is_tvserie: isTv },
|
||||
{ onSuccess: (newEntry) => navigate(`/entry/${newEntry.id}`) }
|
||||
);
|
||||
};
|
||||
|
||||
const confirmRemove = () => {
|
||||
@@ -90,10 +113,22 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) {
|
||||
}
|
||||
};
|
||||
|
||||
const toggleFavorite = () => {
|
||||
if (libraryEntry) {
|
||||
updateEntry.mutate({ id: libraryEntry.id, data: { favorit: !libraryEntry.favorit } });
|
||||
}
|
||||
};
|
||||
|
||||
const toggleHidden = () => {
|
||||
if (libraryEntry) {
|
||||
updateEntry.mutate({ id: libraryEntry.id, data: { hidden: !libraryEntry.hidden } });
|
||||
}
|
||||
};
|
||||
|
||||
const card = (
|
||||
<div className="group relative overflow-hidden rounded-lg transition-all duration-300 hover:scale-[1.02] hover:shadow-xl animate-in fade-in zoom-in-95">
|
||||
{/* Poster */}
|
||||
<div className="relative aspect-[2/3] w-full overflow-hidden rounded-lg bg-muted">
|
||||
<div className="relative aspect-2/3 w-full overflow-hidden rounded-lg bg-muted">
|
||||
<img
|
||||
src={posterUrl}
|
||||
alt={title}
|
||||
@@ -108,9 +143,97 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) {
|
||||
</Badge>
|
||||
)}
|
||||
|
||||
{/* Favorite indicator */}
|
||||
{/* Favorite indicator – hidden on hover when actions button shows */}
|
||||
{libraryEntry?.favorit && (
|
||||
<Star className="absolute right-2 top-2 h-4 w-4 fill-yellow-400 text-yellow-400" />
|
||||
<Star className="absolute right-2 top-2 h-4 w-4 fill-yellow-400 text-yellow-400 transition-opacity group-hover:opacity-0" />
|
||||
)}
|
||||
|
||||
{/* 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>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={(e) => { e.preventDefault(); e.stopPropagation(); }}
|
||||
>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-52" onClick={(e) => e.stopPropagation()}>
|
||||
{/* Watch & Rate */}
|
||||
<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); }}>
|
||||
<Star className="mr-2 h-4 w-4" />
|
||||
Rate this
|
||||
</DropdownMenuItem>
|
||||
{!isTv && (
|
||||
<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>
|
||||
<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(); }}>
|
||||
<EyeOff className="mr-2 h-4 w-4" />
|
||||
{libraryEntry?.hidden ? 'Unhide' : 'Hide'}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
{/* Manage */}
|
||||
<DropdownMenuItem
|
||||
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'}
|
||||
</DropdownMenuItem>
|
||||
<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); }}>
|
||||
<Settings className="mr-2 h-4 w-4" />
|
||||
Settings
|
||||
</DropdownMenuItem>
|
||||
{/* Collection removal */}
|
||||
{collectionId && onRemoveFromCollection && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => { e.stopPropagation(); setShowRemoveCollectionConfirm(true); }}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
<X className="mr-2 h-4 w-4" />
|
||||
Remove from collection
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)}
|
||||
<DropdownMenuSeparator />
|
||||
{/* Danger */}
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => { e.stopPropagation(); setShowConfirm(true); }}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
<Trash2 className="mr-2 h-4 w-4" />
|
||||
Delete entry
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Entry type pill */}
|
||||
@@ -124,7 +247,7 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) {
|
||||
)}
|
||||
|
||||
{/* Hover overlay */}
|
||||
<div className="absolute inset-0 flex flex-col justify-end bg-gradient-to-t from-black/90 via-black/40 to-transparent opacity-0 transition-opacity duration-200 group-hover:opacity-100">
|
||||
<div className="absolute inset-0 flex flex-col justify-end bg-linear-to-t from-black/90 via-black/40 to-transparent opacity-0 transition-opacity duration-200 group-hover:opacity-100">
|
||||
<div className="p-3 space-y-1">
|
||||
<p className="text-sm font-semibold text-white line-clamp-2">
|
||||
{title}
|
||||
@@ -140,24 +263,9 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) {
|
||||
{runtime && <span>{runtime}</span>}
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="pt-1">
|
||||
{isInLibrary ? (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
className="h-7 w-full text-xs"
|
||||
onClick={handleRemove}
|
||||
disabled={deleteEntry.isPending}
|
||||
>
|
||||
{deleteEntry.isPending ? (
|
||||
<Loader2 className="mr-1 h-3 w-3 animate-spin" />
|
||||
) : (
|
||||
<Trash2 className="mr-1 h-3 w-3" />
|
||||
)}
|
||||
{deleteEntry.isPending ? 'Removing...' : 'Remove'}
|
||||
</Button>
|
||||
) : tmdbEntry ? (
|
||||
{/* Add to Library – only for non-library entries */}
|
||||
{!isInLibrary && tmdbEntry && (
|
||||
<div className="pt-1">
|
||||
<Button
|
||||
size="sm"
|
||||
className="h-7 w-full text-xs"
|
||||
@@ -171,8 +279,13 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) {
|
||||
)}
|
||||
{createEntry.isPending ? 'Adding...' : 'Add to Library'}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -184,87 +297,119 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) {
|
||||
{entryLink ? (
|
||||
<Link to={entryLink}>{card}</Link>
|
||||
) : (
|
||||
<div className="cursor-pointer" onClick={() => setShowDetailDialog(true)}>
|
||||
{card}
|
||||
</div>
|
||||
card
|
||||
)}
|
||||
<ConfirmDialog
|
||||
open={showConfirm}
|
||||
onOpenChange={setShowConfirm}
|
||||
title="Remove from Library"
|
||||
description={`Are you sure you want to remove "${title}" from your library? This action cannot be undone.`}
|
||||
confirmLabel="Remove"
|
||||
title="Delete Entry"
|
||||
description={`Are you sure you want to delete "${title}" from your library? This action cannot be undone.`}
|
||||
confirmLabel="Delete"
|
||||
onConfirm={confirmRemove}
|
||||
variant="destructive"
|
||||
/>
|
||||
{/* Details dialog for non-library entries */}
|
||||
{!entryLink && tmdbEntry && (
|
||||
<Dialog open={showDetailDialog} onOpenChange={setShowDetailDialog}>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{title}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="flex gap-4">
|
||||
<img
|
||||
src={posterUrl}
|
||||
alt={title}
|
||||
className="h-48 w-32 shrink-0 rounded-lg object-cover"
|
||||
/>
|
||||
<div className="flex-1 space-y-2 min-w-0">
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm text-muted-foreground">
|
||||
{year && (
|
||||
<span className="flex items-center gap-1">
|
||||
<Calendar className="h-3 w-3" />
|
||||
{year}
|
||||
</span>
|
||||
)}
|
||||
{isTv ? (
|
||||
<Badge variant="secondary" className="text-[10px]">TV Series</Badge>
|
||||
) : (
|
||||
<Badge variant="secondary" className="text-[10px]">Movie</Badge>
|
||||
)}
|
||||
</div>
|
||||
{tmdbEntry.vote_average > 0 && (
|
||||
<div className="flex items-center gap-1 text-sm">
|
||||
<Star className="h-3.5 w-3.5 fill-yellow-400 text-yellow-400" />
|
||||
<span>{tmdbEntry.vote_average.toFixed(1)}/10</span>
|
||||
</div>
|
||||
)}
|
||||
{tmdbEntry.overview && (
|
||||
<p className="text-sm text-muted-foreground line-clamp-6">
|
||||
{tmdbEntry.overview}
|
||||
</p>
|
||||
)}
|
||||
<Button
|
||||
size="sm"
|
||||
className="mt-2"
|
||||
onClick={(ev) => {
|
||||
ev.stopPropagation();
|
||||
handleAdd(ev);
|
||||
setShowDetailDialog(false);
|
||||
}}
|
||||
disabled={createEntry.isPending}
|
||||
>
|
||||
{createEntry.isPending ? (
|
||||
<Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" />
|
||||
) : (
|
||||
<Plus className="mr-1.5 h-3.5 w-3.5" />
|
||||
)}
|
||||
{createEntry.isPending ? 'Adding...' : 'Add to Library'}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
{collectionId && onRemoveFromCollection && (
|
||||
<ConfirmDialog
|
||||
open={showRemoveCollectionConfirm}
|
||||
onOpenChange={setShowRemoveCollectionConfirm}
|
||||
title="Remove from Collection"
|
||||
description={`Remove "${title}" from this collection?`}
|
||||
confirmLabel="Remove"
|
||||
onConfirm={() => {
|
||||
if (libraryEntry) onRemoveFromCollection(libraryEntry.id);
|
||||
setShowRemoveCollectionConfirm(false);
|
||||
}}
|
||||
variant="destructive"
|
||||
/>
|
||||
)}
|
||||
{libraryEntry && showSeenDialog && (
|
||||
<LazyEntrySeenDialog
|
||||
entry={libraryEntry}
|
||||
open={showSeenDialog}
|
||||
onOpenChange={setShowSeenDialog}
|
||||
/>
|
||||
)}
|
||||
{libraryEntry && showRatingDialog && (
|
||||
<RatingDialog
|
||||
open={showRatingDialog}
|
||||
onOpenChange={setShowRatingDialog}
|
||||
entry={libraryEntry}
|
||||
/>
|
||||
)}
|
||||
{libraryEntry && showWatchHistoryDialog && (
|
||||
<LazyMovieWatchHistoryDialog
|
||||
entryId={libraryEntry.id}
|
||||
open={showWatchHistoryDialog}
|
||||
onOpenChange={setShowWatchHistoryDialog}
|
||||
/>
|
||||
)}
|
||||
{libraryEntry && showCollectionDialog && (
|
||||
<AddEntryToCollectionDialog
|
||||
open={showCollectionDialog}
|
||||
onOpenChange={setShowCollectionDialog}
|
||||
entryId={libraryEntry.id}
|
||||
/>
|
||||
)}
|
||||
{libraryEntry && showMediaDialog && (
|
||||
<EntryMediaDialog
|
||||
open={showMediaDialog}
|
||||
onOpenChange={setShowMediaDialog}
|
||||
entryId={libraryEntry.id}
|
||||
medias={libraryEntry.medias || []}
|
||||
/>
|
||||
)}
|
||||
{libraryEntry && showSettingsDialog && (
|
||||
<EntrySettingsDialog
|
||||
open={showSettingsDialog}
|
||||
onOpenChange={setShowSettingsDialog}
|
||||
entry={libraryEntry}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/* Lazy wrappers – only mount when dialog is open so hooks fetch on demand */
|
||||
|
||||
function LazyEntrySeenDialog({ entry, open, onOpenChange }: {
|
||||
entry: Entry;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}) {
|
||||
const { data: seasons = [] } = useEntrySeasons(entry.id);
|
||||
return (
|
||||
<EntrySeenDialog
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
entry={entry}
|
||||
seasons={seasons}
|
||||
mode="add"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function LazyMovieWatchHistoryDialog({ entryId, open, onOpenChange }: {
|
||||
entryId: number;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}) {
|
||||
const { data: watchHistory = [] } = useEntrySeenByEntry(entryId);
|
||||
const deleteEntrySeen = useDeleteEntrySeen();
|
||||
return (
|
||||
<MovieWatchHistoryDialog
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
entryId={entryId}
|
||||
watchHistory={watchHistory}
|
||||
onDelete={(seenId) => deleteEntrySeen.mutate({ id: seenId, entryId })}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function EntryCardSkeleton() {
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="aspect-[2/3] w-full rounded-lg" />
|
||||
<Skeleton className="aspect-2/3 w-full rounded-lg" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user