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
|
// * GET - ALL EPISODE SEEN
|
||||||
episodeSeenRouter.get('/', episodeSeenController.getEpisodesSeen);
|
episodeSeenRouter.get('/', episodeSeenController.getEpisodesSeen);
|
||||||
|
|
||||||
// * GET - EPISODE SEEN BY ID
|
// * GET - EPISODE SEEN BY EPISODE ID (must come before /:id)
|
||||||
episodeSeenRouter.get('/:id', episodeSeenController.getEpisodeSeenById);
|
|
||||||
|
|
||||||
// * GET - EPISODE SEEN BY EPISODE ID
|
|
||||||
episodeSeenRouter.get('/by-episode/:episodeId', episodeSeenController.getEpisodeSeensByEpisodeId);
|
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);
|
episodeSeenRouter.get('/by-entry/:entryId', episodeSeenController.getEpisodeSeensByEntryId);
|
||||||
|
|
||||||
|
// * GET - EPISODE SEEN BY ID
|
||||||
|
episodeSeenRouter.get('/:id', episodeSeenController.getEpisodeSeenById);
|
||||||
|
|
||||||
// * PUT - UPDATE EPISODE SEEN
|
// * PUT - UPDATE EPISODE SEEN
|
||||||
episodeSeenRouter.put('/:id', episodeSeenController.updateEpisodeSeen);
|
episodeSeenRouter.put('/:id', episodeSeenController.updateEpisodeSeen);
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export interface TmdbFilmographyItem {
|
|||||||
job?: string;
|
job?: string;
|
||||||
department?: string;
|
department?: string;
|
||||||
credit_id?: string;
|
credit_id?: string;
|
||||||
|
popularity?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TmdbFilmographyResponse {
|
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() {
|
export function useDeleteEpisodeSeen() {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import { format, startOfMonth, endOfMonth, eachDayOfInterval, getDay, addMonths,
|
|||||||
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { useEpisodesByMonth } from '@/hooks/useEpisodes';
|
import { useEpisodesByMonth } from '@/hooks/useEpisodes';
|
||||||
import { getTmdbPosterUrl, getPosterUrl } from '@/lib/media-utils';
|
|
||||||
import { Tooltip, TooltipContent, TooltipTrigger, TooltipProvider } from '@/components/ui/tooltip';
|
import { Tooltip, TooltipContent, TooltipTrigger, TooltipProvider } from '@/components/ui/tooltip';
|
||||||
|
import { getTmdbPosterUrl } from '@/lib/media-utils';
|
||||||
import type { Episode } from '@/types';
|
import type { Episode } from '@/types';
|
||||||
|
|
||||||
const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||||
@@ -123,13 +123,7 @@ export function CalendarPage() {
|
|||||||
|
|
||||||
function EpisodeCalendarItem({ episode }: { episode: Episode }) {
|
function EpisodeCalendarItem({ episode }: { episode: Episode }) {
|
||||||
type EpisodeWithEntry = Episode & {
|
type EpisodeWithEntry = Episode & {
|
||||||
entry?: {
|
entry?: { id: number; title?: string; poster_path?: string | null };
|
||||||
id: number;
|
|
||||||
title?: string;
|
|
||||||
poster_path?: string | null;
|
|
||||||
medias?: unknown[];
|
|
||||||
isInLibrary?: boolean;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
const ep = episode as EpisodeWithEntry;
|
const ep = episode as EpisodeWithEntry;
|
||||||
const entry = ep.entry;
|
const entry = ep.entry;
|
||||||
@@ -137,29 +131,29 @@ function EpisodeCalendarItem({ episode }: { episode: Episode }) {
|
|||||||
const entryTitle = entry?.title ?? '';
|
const entryTitle = entry?.title ?? '';
|
||||||
const seasonId = episode.season_id;
|
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 seasonLabel = `S${String(seasonId).padStart(2, '0')}`;
|
||||||
const episodeLabel = `E${String(episode.episode_number).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 = (
|
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">
|
<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">
|
||||||
{posterSrc && (
|
{thumbSrc && (
|
||||||
<img
|
<img
|
||||||
src={posterSrc}
|
src={thumbSrc}
|
||||||
alt=""
|
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">
|
<p className="text-[10px] font-medium truncate leading-tight">
|
||||||
{entryTitle}
|
{entryTitle || 'Unknown'}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-[9px] text-muted-foreground tabular-nums">
|
<p className="text-[9px] text-muted-foreground tabular-nums leading-tight">
|
||||||
{seasonLabel} {episodeLabel}
|
{seasonLabel} {episodeLabel}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -181,13 +175,15 @@ function EpisodeCalendarItem({ episode }: { episode: Episode }) {
|
|||||||
)}
|
)}
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent side="right" className="max-w-50">
|
<TooltipContent side="right" className="max-w-50">
|
||||||
|
<div className="space-y-0.5">
|
||||||
<p className="text-xs font-semibold">{entryTitle}</p>
|
<p className="text-xs font-semibold">{entryTitle}</p>
|
||||||
{episode.name && (
|
{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}
|
{seasonLabel} {episodeLabel}
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -189,14 +189,14 @@ export function EntryDetailsPage() {
|
|||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{director && (
|
{director?.people?.name && (
|
||||||
<p className="text-sm text-muted-foreground">
|
<p className="text-sm text-muted-foreground">
|
||||||
by{' '}
|
by{' '}
|
||||||
<Link
|
<Link
|
||||||
to={`/people/${director.people_id}`}
|
to={`/people/${director.people_id}`}
|
||||||
className="font-medium text-foreground hover:underline"
|
className="font-medium text-foreground hover:underline"
|
||||||
>
|
>
|
||||||
{director.people?.name}
|
{director.people.name}
|
||||||
</Link>
|
</Link>
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
import { useState } from 'react';
|
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 { useQuery } from '@tanstack/react-query';
|
||||||
import { seasonsApi } from '@/api/seasons';
|
import { seasonsApi } from '@/api/seasons';
|
||||||
import { useEpisodeSeenByEpisode, useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen';
|
import {
|
||||||
|
useEpisodeSeenByEpisode,
|
||||||
|
useDeleteEpisodeSeen,
|
||||||
|
} from '@/hooks/useEpisodeSeen';
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Separator } from '@/components/ui/separator';
|
import { Separator } from '@/components/ui/separator';
|
||||||
import { EpisodeWatchHistory } from '@/components/entries/EpisodeWatchHistory';
|
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 { CastList } from '@/components/entries/CastList';
|
||||||
import { Eye, ChevronLeft, ChevronRight, Clock } from 'lucide-react';
|
import { Eye, ChevronLeft, ChevronRight, Clock } from 'lucide-react';
|
||||||
import { getTmdbPosterUrl, formatDate, formatRuntime } from '@/lib/media-utils';
|
import { getTmdbPosterUrl, formatDate, formatRuntime } from '@/lib/media-utils';
|
||||||
import type { Episode } from '@/types';
|
import type { Episode, EpisodeSeen } from '@/types';
|
||||||
|
|
||||||
export function EpisodePage() {
|
export function EpisodePage() {
|
||||||
const { entryId, seasonId, episodeId } = useParams<{
|
const { entryId, seasonId, episodeId } = useParams<{
|
||||||
@@ -18,6 +23,7 @@ export function EpisodePage() {
|
|||||||
seasonId: string;
|
seasonId: string;
|
||||||
episodeId: string;
|
episodeId: string;
|
||||||
}>();
|
}>();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { data: episodes = [] } = useQuery({
|
const { data: episodes = [] } = useQuery({
|
||||||
queryKey: ['seasons', parseInt(seasonId!, 10), 'episodes'],
|
queryKey: ['seasons', parseInt(seasonId!, 10), 'episodes'],
|
||||||
@@ -25,9 +31,15 @@ export function EpisodePage() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const epId = parseInt(episodeId!, 10);
|
const epId = parseInt(episodeId!, 10);
|
||||||
|
const entryIdNum = parseInt(entryId!, 10);
|
||||||
const episode: Episode | undefined = episodes.find((ep: Episode) => ep.id === epId);
|
const episode: Episode | undefined = episodes.find((ep: Episode) => ep.id === epId);
|
||||||
const { data: watchHistory = [] } = useEpisodeSeenByEpisode(epId);
|
const { data: watchHistory = [] } = useEpisodeSeenByEpisode(epId);
|
||||||
const createEpisodeSeen = useCreateEpisodeSeen();
|
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
|
// Find prev/next episode
|
||||||
const currentIndex = episodes.findIndex((ep: Episode) => ep.id === epId);
|
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 (
|
return (
|
||||||
<div className="space-y-8">
|
<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 && (
|
{episode.still_path && (
|
||||||
<div className="overflow-hidden rounded-lg">
|
<div className="overflow-hidden rounded-xl">
|
||||||
<img
|
<img
|
||||||
src={getTmdbPosterUrl(episode.still_path, 'w780')}
|
src={getTmdbPosterUrl(episode.still_path, 'w1280')}
|
||||||
alt={episode.name}
|
alt={episode.name}
|
||||||
className="w-full max-h-80 object-cover"
|
className="w-full max-h-96 object-cover"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Info */}
|
{/* Info */}
|
||||||
<div className="space-y-3">
|
<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>
|
<h1 className="text-2xl font-bold">{episode.name}</h1>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex flex-wrap items-center gap-3 text-sm text-muted-foreground">
|
<div className="flex flex-wrap items-center gap-3 text-sm text-muted-foreground">
|
||||||
{episode.air_date && <span>{formatDate(episode.air_date)}</span>}
|
{episode.air_date && <span>{formatDate(episode.air_date)}</span>}
|
||||||
@@ -90,11 +102,6 @@ export function EpisodePage() {
|
|||||||
{episode.overview}
|
{episode.overview}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Button size="sm" onClick={handleMarkWatched}>
|
|
||||||
<Eye className="mr-1 h-4 w-4" />
|
|
||||||
Mark as Watched
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Guest Stars */}
|
{/* Guest Stars */}
|
||||||
@@ -109,38 +116,93 @@ export function EpisodePage() {
|
|||||||
{watchHistory.length > 0 && (
|
{watchHistory.length > 0 && (
|
||||||
<>
|
<>
|
||||||
<Separator />
|
<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 />
|
<Separator />
|
||||||
<div className="flex justify-between">
|
<div className="flex items-center justify-between gap-2">
|
||||||
{prevEpisode ? (
|
{prevEpisode ? (
|
||||||
<Button variant="outline" asChild>
|
<Button
|
||||||
<Link
|
variant="outline"
|
||||||
to={`/entry/${entryId}/season/${seasonId}/episode/${prevEpisode.id}`}
|
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}
|
E{prevEpisode.episode_number}: {prevEpisode.name}
|
||||||
</Link>
|
</span>
|
||||||
</Button>
|
</Button>
|
||||||
) : (
|
) : (
|
||||||
<div />
|
<div />
|
||||||
)}
|
)}
|
||||||
{nextEpisode ? (
|
{nextEpisode ? (
|
||||||
<Button variant="outline" asChild>
|
<Button
|
||||||
<Link
|
variant="outline"
|
||||||
to={`/entry/${entryId}/season/${seasonId}/episode/${nextEpisode.id}`}
|
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}
|
E{nextEpisode.episode_number}: {nextEpisode.name}
|
||||||
<ChevronRight className="ml-1 h-4 w-4" />
|
</span>
|
||||||
</Link>
|
<ChevronRight className="h-4 w-4 shrink-0" />
|
||||||
</Button>
|
</Button>
|
||||||
) : (
|
) : (
|
||||||
<div />
|
<div />
|
||||||
)}
|
)}
|
||||||
</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>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
|
import { useState } from 'react';
|
||||||
import { usePerson, usePersonTmdbFilmography } from '@/hooks/usePeople';
|
import { usePerson, usePersonTmdbFilmography } from '@/hooks/usePeople';
|
||||||
import { useLibrary } from '@/hooks/useEntries';
|
import { useLibrary } from '@/hooks/useEntries';
|
||||||
import { useLibraryStore } from '@/stores/useLibraryStore';
|
import { useLibraryStore } from '@/stores/useLibraryStore';
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||||
import { Separator } from '@/components/ui/separator';
|
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 { EntryCard } from '@/components/entries/EntryCard';
|
||||||
import { getProfileUrl, formatDate } from '@/lib/media-utils';
|
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';
|
import type { TmdbFilmographyItem } from '@/api/people';
|
||||||
|
|
||||||
export function PersonDetailsPage() {
|
export function PersonDetailsPage() {
|
||||||
@@ -80,12 +82,17 @@ interface FilmographySectionProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLoading }: 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) {
|
if (tmdbLoading || !libraryLoaded) {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<h2 className="text-xl font-semibold">Filmography</h2>
|
<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">
|
<div className={GRID}>
|
||||||
{Array.from({ length: 10 }).map((_, i) => (
|
{Array.from({ length: 6 }).map((_, i) => (
|
||||||
<Skeleton key={i} className="aspect-2/3 rounded-lg" />
|
<Skeleton key={i} className="aspect-2/3 rounded-lg" />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -111,10 +118,12 @@ function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const libraryCredits = dedupedCredits.filter((c) => tmdbIdToLibraryEntry.has(c.id));
|
// Sort by popularity descending
|
||||||
const otherCredits = dedupedCredits.filter((c) => !tmdbIdToLibraryEntry.has(c.id));
|
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 (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<h2 className="text-xl font-semibold">Filmography</h2>
|
<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 (
|
return (
|
||||||
<div className="space-y-8">
|
<div className="space-y-8">
|
||||||
<h2 className="text-xl font-semibold">Filmography</h2>
|
<h2 className="text-xl font-semibold">Filmography</h2>
|
||||||
|
|
||||||
{libraryCredits.length > 0 && (
|
{libraryCredits.length > 0 && (
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<h3 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">In Your Library</h3>
|
<div className="flex items-center justify-between">
|
||||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5">
|
<h3 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">
|
||||||
{libraryCredits.map((credit) => {
|
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)!;
|
const entry = tmdbIdToLibraryEntry.get(credit.id)!;
|
||||||
return (
|
return (
|
||||||
<div key={credit.id} className="space-y-1">
|
<div key={credit.id} className="space-y-1">
|
||||||
@@ -148,23 +187,52 @@ function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLo
|
|||||||
|
|
||||||
{otherCredits.length > 0 && (
|
{otherCredits.length > 0 && (
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<h3 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">Not in Library</h3>
|
<div className="flex items-center justify-between">
|
||||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5">
|
<h3 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">
|
||||||
{otherCredits.map((credit) => {
|
Not in Library ({otherCredits.length})
|
||||||
const title = credit.title ?? credit.name ?? 'Unknown';
|
</h3>
|
||||||
const posterSrc = credit.poster_path
|
{otherTotalPages > 1 && (
|
||||||
? getTmdbImageUrl(credit.poster_path, 'w342')
|
<div className="flex items-center gap-1">
|
||||||
: '/images/default-poster.png';
|
<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 (
|
return (
|
||||||
<div key={credit.id} className="space-y-1">
|
<div key={credit.id} className="space-y-1">
|
||||||
<div className="relative aspect-2/3 overflow-hidden rounded-lg bg-muted">
|
<EntryCard tmdbEntry={tmdbEntry} />
|
||||||
<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>
|
|
||||||
{credit.character && (
|
{credit.character && (
|
||||||
<p className="text-xs text-muted-foreground text-center line-clamp-1 px-1">{credit.character}</p>
|
<p className="text-xs text-muted-foreground text-center line-clamp-1 px-1">{credit.character}</p>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in new issue
Block a user