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,6 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { useState, useMemo } from 'react';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { useCollection, useDeleteCollection, useGetCollectionParts } from '@/hooks/useCollections';
|
||||
import { useCollection, useDeleteCollection, useGetCollectionParts, useRemoveEntryFromCollection } from '@/hooks/useCollections';
|
||||
import { EntryLibraryGrid } from '@/components/entries/EntryLibraryGrid';
|
||||
import { getCollectionPosterUrl } from '@/lib/media-utils';
|
||||
import { getTmdbImageUrl } from '@/lib/api';
|
||||
@@ -12,10 +12,14 @@ import {
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { Star, MoreVertical, Pencil, Download, Trash2 } from 'lucide-react';
|
||||
import { Star, MoreVertical, Pencil, Download, Trash2, ArrowUpDown, ArrowUp, ArrowDown } from 'lucide-react';
|
||||
import { CollectionEditDialog } from '@/components/dialogs/CollectionEditDialog';
|
||||
import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog';
|
||||
import { toast } from 'sonner';
|
||||
import type { Entry } from '@/types';
|
||||
|
||||
type CollectionSortField = 'order' | 'year' | 'title' | 'rating';
|
||||
type SortDir = 'asc' | 'desc';
|
||||
|
||||
export function CollectionDetailsPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
@@ -23,8 +27,11 @@ export function CollectionDetailsPage() {
|
||||
const { data: collection, isLoading, isError } = useCollection(Number(id));
|
||||
const [showEditDialog, setShowEditDialog] = useState(false);
|
||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
||||
const [sortField, setSortField] = useState<CollectionSortField>('order');
|
||||
const [sortDir, setSortDir] = useState<SortDir>('asc');
|
||||
const deleteCollection = useDeleteCollection();
|
||||
const getCollectionParts = useGetCollectionParts();
|
||||
const removeEntryFromCollection = useRemoveEntryFromCollection();
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
@@ -33,7 +40,7 @@ export function CollectionDetailsPage() {
|
||||
<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" />
|
||||
<Skeleton key={i} className="aspect-2/3 w-full rounded-lg" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
@@ -55,6 +62,46 @@ export function CollectionDetailsPage() {
|
||||
isInLibrary: true,
|
||||
}));
|
||||
|
||||
const sortedEntries = useMemo(() => {
|
||||
const sorted = [...entries].sort((a, b) => {
|
||||
let cmp = 0;
|
||||
switch (sortField) {
|
||||
case 'order': {
|
||||
const oa = (a as Entry & { UserCollectionEntry?: { order: number } }).UserCollectionEntry?.order ?? 0;
|
||||
const ob = (b as Entry & { UserCollectionEntry?: { order: number } }).UserCollectionEntry?.order ?? 0;
|
||||
cmp = oa - ob;
|
||||
break;
|
||||
}
|
||||
case 'year': {
|
||||
const ya = a.release_date ? new Date(a.release_date).getFullYear() : 0;
|
||||
const yb = b.release_date ? new Date(b.release_date).getFullYear() : 0;
|
||||
cmp = ya - yb;
|
||||
break;
|
||||
}
|
||||
case 'title':
|
||||
cmp = (a.title || '').localeCompare(b.title || '');
|
||||
break;
|
||||
case 'rating': {
|
||||
const ra = a.entryRatings?.user_rating || a.entryRatings?.tmdb_rating || 0;
|
||||
const rb = b.entryRatings?.user_rating || b.entryRatings?.tmdb_rating || 0;
|
||||
cmp = ra - rb;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sortDir === 'asc' ? cmp : -cmp;
|
||||
});
|
||||
return sorted;
|
||||
}, [entries, sortField, sortDir]);
|
||||
|
||||
const handleSort = (field: CollectionSortField) => {
|
||||
if (field === sortField) {
|
||||
setSortDir((d) => (d === 'asc' ? 'desc' : 'asc'));
|
||||
} else {
|
||||
setSortField(field);
|
||||
setSortDir(field === 'rating' ? 'desc' : 'asc');
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
deleteCollection.mutate(collection.id, {
|
||||
onSuccess: () => navigate('/collections', { replace: true }),
|
||||
@@ -78,7 +125,7 @@ export function CollectionDetailsPage() {
|
||||
) : (
|
||||
<div className="h-48 w-full bg-muted sm:h-64" />
|
||||
)}
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-background via-background/60 to-transparent" />
|
||||
<div className="absolute inset-0 bg-linear-to-t from-background via-background/60 to-transparent" />
|
||||
|
||||
{/* Quick action menu - top right */}
|
||||
<div className="absolute top-3 right-3">
|
||||
@@ -142,8 +189,38 @@ export function CollectionDetailsPage() {
|
||||
</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={entries} isLoading={false} />
|
||||
<EntryLibraryGrid
|
||||
entries={sortedEntries}
|
||||
isLoading={false}
|
||||
collectionId={collection.id}
|
||||
onRemoveFromCollection={(entryId) =>
|
||||
removeEntryFromCollection.mutate({ collectionId: collection.id, entryId })
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Edit dialog */}
|
||||
{showEditDialog && (
|
||||
|
||||
Reference in new issue
Block a user