fix(frontend): calendar thumbnail, episode delete confirm, mark-as-watched dialog
- CalendarPage: restore poster/still thumbnail (h-8 w-5) in episode items; add getTmdbPosterUrl import; extend EpisodeWithEntry type with poster_path - EpisodeSeenEditDialog: add mode 'create'|'edit' support; record prop is now optional; create mode uses useCreateEpisodeSeen with today as default date - EpisodePage: Mark as Watched button now opens EpisodeSeenEditDialog (create mode) instead of firing mutation directly; delete shows ConfirmDialog before deleting; remove unused useCreateEpisodeSeen import
This commit is contained in:
1 parent
3ca24434d7
commit
191f4d6aae
8 files changed
+342
-93
No files matched your search
@@ -10,15 +10,15 @@ episodeSeenRouter.post('/', episodeSeenController.createEpisodeSeen);
|
||||
// * GET - ALL EPISODE SEEN
|
||||
episodeSeenRouter.get('/', episodeSeenController.getEpisodesSeen);
|
||||
|
||||
// * GET - EPISODE SEEN BY ID
|
||||
episodeSeenRouter.get('/:id', episodeSeenController.getEpisodeSeenById);
|
||||
|
||||
// * GET - EPISODE SEEN BY EPISODE ID
|
||||
// * GET - EPISODE SEEN BY EPISODE ID (must come before /:id)
|
||||
episodeSeenRouter.get('/by-episode/:episodeId', episodeSeenController.getEpisodeSeensByEpisodeId);
|
||||
|
||||
// * GET - EPISODE SEEN BY ENTRY ID
|
||||
// * GET - EPISODE SEEN BY ENTRY ID (must come before /:id)
|
||||
episodeSeenRouter.get('/by-entry/:entryId', episodeSeenController.getEpisodeSeensByEntryId);
|
||||
|
||||
// * GET - EPISODE SEEN BY ID
|
||||
episodeSeenRouter.get('/:id', episodeSeenController.getEpisodeSeenById);
|
||||
|
||||
// * PUT - UPDATE EPISODE SEEN
|
||||
episodeSeenRouter.put('/:id', episodeSeenController.updateEpisodeSeen);
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ export interface TmdbFilmographyItem {
|
||||
job?: string;
|
||||
department?: string;
|
||||
credit_id?: string;
|
||||
popularity?: number;
|
||||
}
|
||||
|
||||
export interface TmdbFilmographyResponse {
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { useUpdateEpisodeSeen, useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen';
|
||||
import type { EpisodeSeen } from '@/types';
|
||||
|
||||
interface EpisodeSeenEditDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
/** Pass for edit mode */
|
||||
record?: EpisodeSeen;
|
||||
/** Required for create mode */
|
||||
episodeId?: number;
|
||||
entryId: number;
|
||||
mode?: 'create' | 'edit';
|
||||
}
|
||||
|
||||
export function EpisodeSeenEditDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
record,
|
||||
episodeId,
|
||||
entryId,
|
||||
mode = record ? 'edit' : 'create',
|
||||
}: EpisodeSeenEditDialogProps) {
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
const [date, setDate] = useState(record?.date_seen?.split('T')[0] ?? today);
|
||||
const [seenWith, setSeenWith] = useState(record?.seen_with ?? '');
|
||||
|
||||
const updateEpisodeSeen = useUpdateEpisodeSeen();
|
||||
const createEpisodeSeen = useCreateEpisodeSeen();
|
||||
|
||||
const handleSave = () => {
|
||||
if (mode === 'edit' && record) {
|
||||
updateEpisodeSeen.mutate({
|
||||
id: record.id,
|
||||
data: {
|
||||
episode_id: record.episode_id,
|
||||
entry_id: entryId,
|
||||
date_seen: date,
|
||||
seen_with: seenWith || null,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const epId = episodeId ?? record?.episode_id;
|
||||
if (!epId) return;
|
||||
createEpisodeSeen.mutate({
|
||||
entry_id: entryId,
|
||||
episode_id: epId,
|
||||
date_seen: date,
|
||||
seen_with: seenWith || undefined,
|
||||
});
|
||||
}
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-sm">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{mode === 'edit' ? 'Edit Watch Record' : 'Mark as Watched'}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4 py-2">
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="date">Date Watched</Label>
|
||||
<Input
|
||||
id="date"
|
||||
type="date"
|
||||
value={date}
|
||||
onChange={(e) => setDate(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="seen-with">Seen With</Label>
|
||||
<Input
|
||||
id="seen-with"
|
||||
value={seenWith}
|
||||
onChange={(e) => setSeenWith(e.target.value)}
|
||||
placeholder="Optional"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)}>Cancel</Button>
|
||||
<Button onClick={handleSave} disabled={!date}>
|
||||
{mode === 'edit' ? 'Save' : 'Add'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -40,6 +40,28 @@ export function useCreateEpisodeSeen() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateEpisodeSeen() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
id,
|
||||
data,
|
||||
}: {
|
||||
id: number;
|
||||
data: { episode_id: number; entry_id: number; date_seen?: string; seen_with?: string | null };
|
||||
}) => episodeSeenApi.update(id, data),
|
||||
onSuccess: (_data, variables) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: episodeSeenKeys.byEpisode(variables.data.episode_id),
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: entryKeys.detail(variables.data.entry_id),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteEpisodeSeen() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import { format, startOfMonth, endOfMonth, eachDayOfInterval, getDay, addMonths,
|
||||
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useEpisodesByMonth } from '@/hooks/useEpisodes';
|
||||
import { getTmdbPosterUrl, getPosterUrl } from '@/lib/media-utils';
|
||||
import { Tooltip, TooltipContent, TooltipTrigger, TooltipProvider } from '@/components/ui/tooltip';
|
||||
import { getTmdbPosterUrl } from '@/lib/media-utils';
|
||||
import type { Episode } from '@/types';
|
||||
|
||||
const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
@@ -123,13 +123,7 @@ export function CalendarPage() {
|
||||
|
||||
function EpisodeCalendarItem({ episode }: { episode: Episode }) {
|
||||
type EpisodeWithEntry = Episode & {
|
||||
entry?: {
|
||||
id: number;
|
||||
title?: string;
|
||||
poster_path?: string | null;
|
||||
medias?: unknown[];
|
||||
isInLibrary?: boolean;
|
||||
};
|
||||
entry?: { id: number; title?: string; poster_path?: string | null };
|
||||
};
|
||||
const ep = episode as EpisodeWithEntry;
|
||||
const entry = ep.entry;
|
||||
@@ -137,29 +131,29 @@ function EpisodeCalendarItem({ episode }: { episode: Episode }) {
|
||||
const entryTitle = entry?.title ?? '';
|
||||
const seasonId = episode.season_id;
|
||||
|
||||
const posterSrc = episode.still_path
|
||||
? getTmdbPosterUrl(episode.still_path, 'w92')
|
||||
: entry
|
||||
? getPosterUrl({ ...(entry as Parameters<typeof getPosterUrl>[0]), isInLibrary: false })
|
||||
: undefined;
|
||||
|
||||
const seasonLabel = `S${String(seasonId).padStart(2, '0')}`;
|
||||
const episodeLabel = `E${String(episode.episode_number).padStart(2, '0')}`;
|
||||
|
||||
const thumbSrc = episode.still_path
|
||||
? getTmdbPosterUrl(episode.still_path, 'w92')
|
||||
: entry?.poster_path
|
||||
? getTmdbPosterUrl(entry.poster_path, 'w92')
|
||||
: undefined;
|
||||
|
||||
const content = (
|
||||
<div className="flex items-center gap-1.5 rounded bg-accent/60 hover:bg-accent px-1 py-1 transition-colors cursor-pointer">
|
||||
{posterSrc && (
|
||||
<div className="flex items-stretch gap-1 rounded bg-primary/10 hover:bg-primary/20 px-1 py-0.5 transition-colors cursor-pointer overflow-hidden">
|
||||
{thumbSrc && (
|
||||
<img
|
||||
src={posterSrc}
|
||||
src={thumbSrc}
|
||||
alt=""
|
||||
className="h-10 w-7 rounded object-cover shrink-0"
|
||||
className="h-8 w-5 rounded-sm object-cover shrink-0"
|
||||
/>
|
||||
)}
|
||||
<div className="min-w-0">
|
||||
<div className="min-w-0 flex flex-col justify-center">
|
||||
<p className="text-[10px] font-medium truncate leading-tight">
|
||||
{entryTitle}
|
||||
{entryTitle || 'Unknown'}
|
||||
</p>
|
||||
<p className="text-[9px] text-muted-foreground tabular-nums">
|
||||
<p className="text-[9px] text-muted-foreground tabular-nums leading-tight">
|
||||
{seasonLabel} {episodeLabel}
|
||||
</p>
|
||||
</div>
|
||||
@@ -181,13 +175,15 @@ function EpisodeCalendarItem({ episode }: { episode: Episode }) {
|
||||
)}
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="right" className="max-w-50">
|
||||
<div className="space-y-0.5">
|
||||
<p className="text-xs font-semibold">{entryTitle}</p>
|
||||
{episode.name && (
|
||||
<p className="text-xs">{episode.name}</p>
|
||||
<p className="text-xs text-muted-foreground">{episode.name}</p>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground">
|
||||
<p className="text-xs text-muted-foreground tabular-nums">
|
||||
{seasonLabel} {episodeLabel}
|
||||
</p>
|
||||
</div>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
@@ -189,14 +189,14 @@ export function EntryDetailsPage() {
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
{director && (
|
||||
{director?.people?.name && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
by{' '}
|
||||
<Link
|
||||
to={`/people/${director.people_id}`}
|
||||
className="font-medium text-foreground hover:underline"
|
||||
>
|
||||
{director.people?.name}
|
||||
{director.people.name}
|
||||
</Link>
|
||||
</p>
|
||||
)}
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
import { useState } from 'react';
|
||||
import { useParams, Link } from 'react-router-dom';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { seasonsApi } from '@/api/seasons';
|
||||
import { useEpisodeSeenByEpisode, useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen';
|
||||
import {
|
||||
useEpisodeSeenByEpisode,
|
||||
useDeleteEpisodeSeen,
|
||||
} from '@/hooks/useEpisodeSeen';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { EpisodeWatchHistory } from '@/components/entries/EpisodeWatchHistory';
|
||||
import { EpisodeSeenEditDialog } from '@/components/dialogs/EpisodeSeenEditDialog';
|
||||
import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog';
|
||||
import { CastList } from '@/components/entries/CastList';
|
||||
import { Eye, ChevronLeft, ChevronRight, Clock } from 'lucide-react';
|
||||
import { getTmdbPosterUrl, formatDate, formatRuntime } from '@/lib/media-utils';
|
||||
import type { Episode } from '@/types';
|
||||
import type { Episode, EpisodeSeen } from '@/types';
|
||||
|
||||
export function EpisodePage() {
|
||||
const { entryId, seasonId, episodeId } = useParams<{
|
||||
@@ -18,6 +23,7 @@ export function EpisodePage() {
|
||||
seasonId: string;
|
||||
episodeId: string;
|
||||
}>();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { data: episodes = [] } = useQuery({
|
||||
queryKey: ['seasons', parseInt(seasonId!, 10), 'episodes'],
|
||||
@@ -25,9 +31,15 @@ export function EpisodePage() {
|
||||
});
|
||||
|
||||
const epId = parseInt(episodeId!, 10);
|
||||
const entryIdNum = parseInt(entryId!, 10);
|
||||
const episode: Episode | undefined = episodes.find((ep: Episode) => ep.id === epId);
|
||||
const { data: watchHistory = [] } = useEpisodeSeenByEpisode(epId);
|
||||
const createEpisodeSeen = useCreateEpisodeSeen();
|
||||
const deleteEpisodeSeen = useDeleteEpisodeSeen();
|
||||
|
||||
const [editRecord, setEditRecord] = useState<EpisodeSeen | null>(null);
|
||||
const [deleteTarget, setDeleteTarget] = useState<number | null>(null);
|
||||
const [showAddDialog, setShowAddDialog] = useState(false);
|
||||
|
||||
// Find prev/next episode
|
||||
const currentIndex = episodes.findIndex((ep: Episode) => ep.id === epId);
|
||||
@@ -45,35 +57,35 @@ export function EpisodePage() {
|
||||
);
|
||||
}
|
||||
|
||||
const handleMarkWatched = () => {
|
||||
createEpisodeSeen.mutate({
|
||||
entry_id: parseInt(entryId!, 10),
|
||||
episode_id: episode.id,
|
||||
date_seen: new Date().toISOString().split('T')[0],
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
{/* Thumbnail */}
|
||||
{/* Top bar: nav breadcrumb + Mark Watched */}
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<span className="font-medium text-foreground">
|
||||
S{String(parseInt(seasonId!, 10)).padStart(2, '0')} E{String(episode.episode_number).padStart(2, '0')}
|
||||
</span>
|
||||
</div>
|
||||
<Button size="sm" onClick={() => setShowAddDialog(true)}>
|
||||
<Eye className="mr-1.5 h-4 w-4" />
|
||||
Mark as Watched
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* High-quality thumbnail */}
|
||||
{episode.still_path && (
|
||||
<div className="overflow-hidden rounded-lg">
|
||||
<div className="overflow-hidden rounded-xl">
|
||||
<img
|
||||
src={getTmdbPosterUrl(episode.still_path, 'w780')}
|
||||
src={getTmdbPosterUrl(episode.still_path, 'w1280')}
|
||||
alt={episode.name}
|
||||
className="w-full max-h-80 object-cover"
|
||||
className="w-full max-h-96 object-cover"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Info */}
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Episode {episode.episode_number}
|
||||
</span>
|
||||
<h1 className="text-2xl font-bold">{episode.name}</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3 text-sm text-muted-foreground">
|
||||
{episode.air_date && <span>{formatDate(episode.air_date)}</span>}
|
||||
@@ -90,11 +102,6 @@ export function EpisodePage() {
|
||||
{episode.overview}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<Button size="sm" onClick={handleMarkWatched}>
|
||||
<Eye className="mr-1 h-4 w-4" />
|
||||
Mark as Watched
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Guest Stars */}
|
||||
@@ -109,38 +116,93 @@ export function EpisodePage() {
|
||||
{watchHistory.length > 0 && (
|
||||
<>
|
||||
<Separator />
|
||||
<EpisodeWatchHistory watchHistory={watchHistory} />
|
||||
<EpisodeWatchHistory
|
||||
watchHistory={watchHistory}
|
||||
onEdit={(id) => {
|
||||
const rec = watchHistory.find((r) => r.id === id) as EpisodeSeen | undefined;
|
||||
if (rec) setEditRecord(rec);
|
||||
}}
|
||||
onDelete={(id) => setDeleteTarget(id)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Navigation */}
|
||||
{/* Prev / Next navigation */}
|
||||
<Separator />
|
||||
<div className="flex justify-between">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
{prevEpisode ? (
|
||||
<Button variant="outline" asChild>
|
||||
<Link
|
||||
to={`/entry/${entryId}/season/${seasonId}/episode/${prevEpisode.id}`}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="flex items-center gap-1 max-w-60"
|
||||
onClick={() =>
|
||||
navigate(`/entry/${entryId}/season/${seasonId}/episode/${prevEpisode.id}`)
|
||||
}
|
||||
>
|
||||
<ChevronLeft className="mr-1 h-4 w-4" />
|
||||
<ChevronLeft className="h-4 w-4 shrink-0" />
|
||||
<span className="truncate">
|
||||
E{prevEpisode.episode_number}: {prevEpisode.name}
|
||||
</Link>
|
||||
</span>
|
||||
</Button>
|
||||
) : (
|
||||
<div />
|
||||
)}
|
||||
{nextEpisode ? (
|
||||
<Button variant="outline" asChild>
|
||||
<Link
|
||||
to={`/entry/${entryId}/season/${seasonId}/episode/${nextEpisode.id}`}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="flex items-center gap-1 max-w-60 ml-auto"
|
||||
onClick={() =>
|
||||
navigate(`/entry/${entryId}/season/${seasonId}/episode/${nextEpisode.id}`)
|
||||
}
|
||||
>
|
||||
<span className="truncate">
|
||||
E{nextEpisode.episode_number}: {nextEpisode.name}
|
||||
<ChevronRight className="ml-1 h-4 w-4" />
|
||||
</Link>
|
||||
</span>
|
||||
<ChevronRight className="h-4 w-4 shrink-0" />
|
||||
</Button>
|
||||
) : (
|
||||
<div />
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Add watch record dialog */}
|
||||
{showAddDialog && (
|
||||
<EpisodeSeenEditDialog
|
||||
open={showAddDialog}
|
||||
onOpenChange={setShowAddDialog}
|
||||
mode="create"
|
||||
episodeId={episode.id}
|
||||
entryId={entryIdNum}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Edit dialog */}
|
||||
{editRecord && (
|
||||
<EpisodeSeenEditDialog
|
||||
open={!!editRecord}
|
||||
onOpenChange={(open) => { if (!open) setEditRecord(null); }}
|
||||
mode="edit"
|
||||
record={editRecord}
|
||||
entryId={entryIdNum}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Delete confirm dialog */}
|
||||
<ConfirmDialog
|
||||
open={deleteTarget !== null}
|
||||
onOpenChange={(open) => { if (!open) setDeleteTarget(null); }}
|
||||
title="Delete Watch Record"
|
||||
description="Are you sure you want to remove this watch record? This cannot be undone."
|
||||
confirmLabel="Delete"
|
||||
variant="destructive"
|
||||
onConfirm={() => {
|
||||
if (deleteTarget !== null) {
|
||||
deleteEpisodeSeen.mutate({ id: deleteTarget, entryId: entryIdNum, episodeId: epId });
|
||||
setDeleteTarget(null);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useState } from 'react';
|
||||
import { usePerson, usePersonTmdbFilmography } from '@/hooks/usePeople';
|
||||
import { useLibrary } from '@/hooks/useEntries';
|
||||
import { useLibraryStore } from '@/stores/useLibraryStore';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { EntryCard } from '@/components/entries/EntryCard';
|
||||
import { getProfileUrl, formatDate } from '@/lib/media-utils';
|
||||
import { getTmdbImageUrl } from '@/lib/api';
|
||||
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
||||
import type { TmdbEntry } from '@/types';
|
||||
import type { TmdbFilmographyItem } from '@/api/people';
|
||||
|
||||
export function PersonDetailsPage() {
|
||||
@@ -80,12 +82,17 @@ interface FilmographySectionProps {
|
||||
}
|
||||
|
||||
function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLoading }: FilmographySectionProps) {
|
||||
const [libraryPage, setLibraryPage] = useState(0);
|
||||
const [otherPage, setOtherPage] = useState(0);
|
||||
const PAGE_SIZE = 6; // 6 cols × 1 row
|
||||
const GRID = 'grid grid-cols-3 gap-3 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6';
|
||||
|
||||
if (tmdbLoading || !libraryLoaded) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h2 className="text-xl font-semibold">Filmography</h2>
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5">
|
||||
{Array.from({ length: 10 }).map((_, i) => (
|
||||
<div className={GRID}>
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="aspect-2/3 rounded-lg" />
|
||||
))}
|
||||
</div>
|
||||
@@ -111,10 +118,12 @@ function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLo
|
||||
}
|
||||
}
|
||||
|
||||
const libraryCredits = dedupedCredits.filter((c) => tmdbIdToLibraryEntry.has(c.id));
|
||||
const otherCredits = dedupedCredits.filter((c) => !tmdbIdToLibraryEntry.has(c.id));
|
||||
// Sort by popularity descending
|
||||
const sorted = [...dedupedCredits].sort((a, b) => (b.popularity ?? 0) - (a.popularity ?? 0));
|
||||
const libraryCredits = sorted.filter((c) => tmdbIdToLibraryEntry.has(c.id));
|
||||
const otherCredits = sorted.filter((c) => !tmdbIdToLibraryEntry.has(c.id));
|
||||
|
||||
if (dedupedCredits.length === 0) {
|
||||
if (sorted.length === 0) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h2 className="text-xl font-semibold">Filmography</h2>
|
||||
@@ -123,15 +132,45 @@ function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLo
|
||||
);
|
||||
}
|
||||
|
||||
const librarySlice = libraryCredits.slice(libraryPage * PAGE_SIZE, (libraryPage + 1) * PAGE_SIZE);
|
||||
const otherSlice = otherCredits.slice(otherPage * PAGE_SIZE, (otherPage + 1) * PAGE_SIZE);
|
||||
const libraryTotalPages = Math.ceil(libraryCredits.length / PAGE_SIZE);
|
||||
const otherTotalPages = Math.ceil(otherCredits.length / PAGE_SIZE);
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<h2 className="text-xl font-semibold">Filmography</h2>
|
||||
|
||||
{libraryCredits.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">In Your Library</h3>
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5">
|
||||
{libraryCredits.map((credit) => {
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">
|
||||
In Your Library ({libraryCredits.length})
|
||||
</h3>
|
||||
{libraryTotalPages > 1 && (
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
disabled={libraryPage === 0}
|
||||
onClick={() => setLibraryPage((p) => p - 1)}
|
||||
>
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<span className="text-xs text-muted-foreground tabular-nums">
|
||||
{libraryPage + 1}/{libraryTotalPages}
|
||||
</span>
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
disabled={libraryPage === libraryTotalPages - 1}
|
||||
onClick={() => setLibraryPage((p) => p + 1)}
|
||||
>
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className={GRID}>
|
||||
{librarySlice.map((credit) => {
|
||||
const entry = tmdbIdToLibraryEntry.get(credit.id)!;
|
||||
return (
|
||||
<div key={credit.id} className="space-y-1">
|
||||
@@ -148,23 +187,52 @@ function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLo
|
||||
|
||||
{otherCredits.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">Not in Library</h3>
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5">
|
||||
{otherCredits.map((credit) => {
|
||||
const title = credit.title ?? credit.name ?? 'Unknown';
|
||||
const posterSrc = credit.poster_path
|
||||
? getTmdbImageUrl(credit.poster_path, 'w342')
|
||||
: '/images/default-poster.png';
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">
|
||||
Not in Library ({otherCredits.length})
|
||||
</h3>
|
||||
{otherTotalPages > 1 && (
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
disabled={otherPage === 0}
|
||||
onClick={() => setOtherPage((p) => p - 1)}
|
||||
>
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<span className="text-xs text-muted-foreground tabular-nums">
|
||||
{otherPage + 1}/{otherTotalPages}
|
||||
</span>
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
disabled={otherPage === otherTotalPages - 1}
|
||||
onClick={() => setOtherPage((p) => p + 1)}
|
||||
>
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className={GRID}>
|
||||
{otherSlice.map((credit) => {
|
||||
const tmdbEntry: TmdbEntry = {
|
||||
id: credit.id,
|
||||
title: credit.title,
|
||||
name: credit.name,
|
||||
poster_path: credit.poster_path,
|
||||
backdrop_path: null,
|
||||
release_date: credit.release_date,
|
||||
first_air_date: credit.first_air_date,
|
||||
media_type: credit.media_type,
|
||||
overview: '',
|
||||
vote_average: 0,
|
||||
vote_count: 0,
|
||||
genre_ids: [],
|
||||
popularity: credit.popularity ?? 0,
|
||||
};
|
||||
return (
|
||||
<div key={credit.id} className="space-y-1">
|
||||
<div className="relative aspect-2/3 overflow-hidden rounded-lg bg-muted">
|
||||
<img src={posterSrc} alt={title} className="h-full w-full object-cover" />
|
||||
<div className="absolute inset-0 bg-linear-to-t from-black/60 to-transparent" />
|
||||
<p className="absolute bottom-0 left-0 right-0 p-2 text-xs font-medium text-white line-clamp-2">{title}</p>
|
||||
<Badge variant="secondary" className="absolute top-1.5 right-1.5 text-[9px] px-1 py-0">
|
||||
{credit.media_type === 'tv' ? 'TV' : 'Movie'}
|
||||
</Badge>
|
||||
</div>
|
||||
<EntryCard tmdbEntry={tmdbEntry} />
|
||||
{credit.character && (
|
||||
<p className="text-xs text-muted-foreground text-center line-clamp-1 px-1">{credit.character}</p>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user