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
+350
-101
No files matched your search
@@ -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>
|
||||
<h1 className="text-2xl font-bold">{episode.name}</h1>
|
||||
|
||||
<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}`}
|
||||
>
|
||||
<ChevronLeft className="mr-1 h-4 w-4" />
|
||||
<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="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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user