fix: season episode dialog, mark season watched, episode 404 handling
Seasons Page: - Episode watch button now opens EpisodeSeenEditDialog instead of directly marking as watched, allowing date/seen-with input - Added "Mark Season as Watched" button that sequentially marks all unwatched episodes in the season Episode Page: - Fixed UI not updating after deleting the last episode seen record; the backend returns 404 when no records exist for an episode, which caused the query to error instead of resolving to an empty array. The API layer now catches 404 and returns [] gracefully.
This commit is contained in:
1 parent
984e2c8b50
commit
6bff2055b4
12 files changed
+380
-90
No files matched your search
@@ -1,12 +1,16 @@
|
||||
import { useState } from 'react';
|
||||
import { useParams, Link } from 'react-router-dom';
|
||||
import { useSeason, useSeasonEpisodes } from '@/hooks/useSeasons';
|
||||
import { useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen';
|
||||
import { EpisodeSeenEditDialog } from '@/components/dialogs/EpisodeSeenEditDialog';
|
||||
import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Eye, CheckCircle2 } from 'lucide-react';
|
||||
import { Eye, CheckCircle2, ListChecks } from 'lucide-react';
|
||||
import { getTmdbPosterUrl, getYear, formatDate } from '@/lib/media-utils';
|
||||
import type { Episode } from '@/types';
|
||||
|
||||
export function SeasonPage() {
|
||||
const { entryId, seasonId } = useParams<{
|
||||
@@ -16,6 +20,12 @@ export function SeasonPage() {
|
||||
const { data: season, isLoading } = useSeason(parseInt(seasonId!, 10));
|
||||
const { data: episodes = [] } = useSeasonEpisodes(parseInt(seasonId!, 10));
|
||||
const createEpisodeSeen = useCreateEpisodeSeen();
|
||||
const [dialogEpisode, setDialogEpisode] = useState<Episode | null>(null);
|
||||
const [markingAll, setMarkingAll] = useState(false);
|
||||
const [showMarkAllDialog, setShowMarkAllDialog] = useState(false);
|
||||
const [markAllDate, setMarkAllDate] = useState(new Date().toISOString().split('T')[0]);
|
||||
const [markAllSeenWith, setMarkAllSeenWith] = useState('');
|
||||
const [showMarkAllConfirm, setShowMarkAllConfirm] = useState(false);
|
||||
|
||||
if (isLoading || !season) {
|
||||
return (
|
||||
@@ -49,8 +59,23 @@ export function SeasonPage() {
|
||||
alt={season.name}
|
||||
className="h-56 w-36 shrink-0 rounded-lg object-cover shadow-lg"
|
||||
/>
|
||||
<div className="flex flex-col justify-center space-y-3">
|
||||
<h1 className="text-2xl font-bold">{season.name}</h1>
|
||||
<div className="flex-1 flex flex-col justify-center space-y-3">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<h1 className="text-2xl font-bold">{season.name}</h1>
|
||||
{/* Mark Season as Watched — top right */}
|
||||
{watchedCount < totalEpisodes && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="shrink-0"
|
||||
disabled={markingAll}
|
||||
onClick={() => setShowMarkAllDialog(true)}
|
||||
>
|
||||
<ListChecks className="mr-1.5 h-4 w-4" />
|
||||
{markingAll ? 'Marking...' : 'Mark Season Watched'}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<span>Season {season.season_number}</span>
|
||||
{season.air_date && (
|
||||
@@ -144,14 +169,10 @@ export function SeasonPage() {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
if (!isWatched) {
|
||||
createEpisodeSeen.mutate({
|
||||
entry_id: parseInt(entryId!, 10),
|
||||
episode_id: episode.id,
|
||||
date_seen: new Date().toISOString(),
|
||||
});
|
||||
setDialogEpisode(episode);
|
||||
}
|
||||
}}
|
||||
disabled={isWatched || createEpisodeSeen.isPending}
|
||||
disabled={isWatched}
|
||||
>
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
@@ -160,6 +181,65 @@ export function SeasonPage() {
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Episode Seen Dialog */}
|
||||
{dialogEpisode && (
|
||||
<EpisodeSeenEditDialog
|
||||
open={!!dialogEpisode}
|
||||
onOpenChange={(open) => { if (!open) setDialogEpisode(null); }}
|
||||
mode="create"
|
||||
episodeId={dialogEpisode.id}
|
||||
entryId={parseInt(entryId!, 10)}
|
||||
seasonId={parseInt(seasonId!, 10)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Mark Season Watched — step 1: date/seen-with dialog */}
|
||||
{showMarkAllDialog && (
|
||||
<EpisodeSeenEditDialog
|
||||
open={showMarkAllDialog}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setShowMarkAllDialog(false);
|
||||
}}
|
||||
mode="create"
|
||||
episodeId={-1}
|
||||
entryId={parseInt(entryId!, 10)}
|
||||
seasonId={parseInt(seasonId!, 10)}
|
||||
overrideSubmit={(date, seenWith) => {
|
||||
setMarkAllDate(date);
|
||||
setMarkAllSeenWith(seenWith);
|
||||
setShowMarkAllDialog(false);
|
||||
setShowMarkAllConfirm(true);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Mark Season Watched — step 2: confirmation */}
|
||||
<ConfirmDialog
|
||||
open={showMarkAllConfirm}
|
||||
onOpenChange={setShowMarkAllConfirm}
|
||||
title="Mark Season as Watched"
|
||||
description={`This will mark all ${episodes.filter((ep) => !ep.date_first_seen && (!ep.episodeSeens || ep.episodeSeens.length === 0)).length} unwatched episodes as seen on ${markAllDate}. Continue?`}
|
||||
confirmLabel="Mark All"
|
||||
isLoading={markingAll}
|
||||
onConfirm={async () => {
|
||||
setMarkingAll(true);
|
||||
const unwatched = episodes.filter(
|
||||
(ep) => !ep.date_first_seen && (!ep.episodeSeens || ep.episodeSeens.length === 0)
|
||||
);
|
||||
for (const ep of unwatched) {
|
||||
await createEpisodeSeen.mutateAsync({
|
||||
entry_id: parseInt(entryId!, 10),
|
||||
episode_id: ep.id,
|
||||
date_seen: markAllDate,
|
||||
seen_with: markAllSeenWith || undefined,
|
||||
season_id: parseInt(seasonId!, 10),
|
||||
});
|
||||
}
|
||||
setMarkingAll(false);
|
||||
setShowMarkAllConfirm(false);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user