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
@@ -3,8 +3,8 @@ import { Link } from 'react-router-dom';
|
||||
import { ChevronDown, ChevronUp, Play } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { EpisodeSeenEditDialog } from '@/components/dialogs/EpisodeSeenEditDialog';
|
||||
import { getYear, getTmdbPosterUrl } from '@/lib/media-utils';
|
||||
import { useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen';
|
||||
import type { Season } from '@/types';
|
||||
|
||||
interface SeasonsContainerProps {
|
||||
@@ -65,7 +65,7 @@ function SeasonItem({
|
||||
season: Season;
|
||||
entryId: number;
|
||||
}) {
|
||||
const createEpisodeSeen = useCreateEpisodeSeen();
|
||||
const [dialogOpen, setDialogOpen] = useState(false);
|
||||
const watchedCount =
|
||||
season.episodes?.filter(
|
||||
(ep) => ep.date_first_seen || (ep.episodeSeens && ep.episodeSeens.length > 0)
|
||||
@@ -79,56 +79,63 @@ function SeasonItem({
|
||||
.find((ep) => !ep.date_first_seen && (!ep.episodeSeens || ep.episodeSeens.length === 0));
|
||||
|
||||
return (
|
||||
<Link
|
||||
to={`/entry/${entryId}/season/${season.id}`}
|
||||
className="flex items-center gap-4 rounded-lg border border-border p-3 transition-colors hover:bg-accent/50"
|
||||
>
|
||||
{/* Poster thumbnail */}
|
||||
<div className="h-16 w-11 shrink-0 overflow-hidden rounded bg-muted">
|
||||
<img
|
||||
src={getTmdbPosterUrl(season.poster_path, 'w92')}
|
||||
alt={season.name}
|
||||
className="h-full w-full object-cover"
|
||||
loading="lazy"
|
||||
<>
|
||||
<Link
|
||||
to={`/entry/${entryId}/season/${season.id}`}
|
||||
className="flex items-center gap-4 rounded-lg border border-border p-3 transition-colors hover:bg-accent/50"
|
||||
>
|
||||
{/* Poster thumbnail */}
|
||||
<div className="h-16 w-11 shrink-0 overflow-hidden rounded bg-muted">
|
||||
<img
|
||||
src={getTmdbPosterUrl(season.poster_path, 'w92')}
|
||||
alt={season.name}
|
||||
className="h-full w-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Info */}
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-medium text-sm truncate">{season.name}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{getYear(season.air_date)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 mt-1">
|
||||
<Progress value={progress} className="h-1.5 flex-1" />
|
||||
<span className="text-xs text-muted-foreground shrink-0">
|
||||
{watchedCount}/{totalEpisodes}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Quick watch button - opens dialog */}
|
||||
{nextUnwatched && (
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-8 w-8 shrink-0"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setDialogOpen(true);
|
||||
}}
|
||||
>
|
||||
<Play className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</Link>
|
||||
|
||||
{nextUnwatched && dialogOpen && (
|
||||
<EpisodeSeenEditDialog
|
||||
open={dialogOpen}
|
||||
onOpenChange={setDialogOpen}
|
||||
mode="create"
|
||||
episodeId={nextUnwatched.id}
|
||||
entryId={entryId}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Info */}
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-medium text-sm truncate">{season.name}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{getYear(season.air_date)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 mt-1">
|
||||
<Progress value={progress} className="h-1.5 flex-1" />
|
||||
<span className="text-xs text-muted-foreground shrink-0">
|
||||
{watchedCount}/{totalEpisodes}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Quick watch button */}
|
||||
{nextUnwatched && (
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-8 w-8 shrink-0"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
createEpisodeSeen.mutate({
|
||||
entry_id: entryId,
|
||||
episode_id: nextUnwatched.id,
|
||||
date_seen: new Date().toISOString(),
|
||||
});
|
||||
}}
|
||||
disabled={createEpisodeSeen.isPending}
|
||||
>
|
||||
<Play className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</Link>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user