feat(frontend): add MarkSeasonWatchedDialog with scatter mode
- Create MarkSeasonWatchedDialog replacing two-step EpisodeSeenEditDialog+ConfirmDialog flow - Add scatter mode to distribute episodes across a date range with preview - Always show "Mark Season Watched" button on SeasonPage
This commit is contained in:
1 parent
ce01dc34fa
commit
6aa57cbe71
2 files changed
+332
-68
No files matched your search
@@ -1,17 +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 { useLibraryStore } from '@/stores/useLibraryStore';
|
||||
import { EpisodeSeenEditDialog } from '@/components/dialogs/EpisodeSeenEditDialog';
|
||||
import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog';
|
||||
import { MarkSeasonWatchedDialog } from '@/components/dialogs/MarkSeasonWatchedDialog';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Eye, CheckCircle2, ListChecks } from 'lucide-react';
|
||||
import { getTmdbPosterUrl, getYear, formatDate } from '@/lib/media-utils';
|
||||
import type { Episode } from '@/types';
|
||||
import type { SeenAccuracy } from '@/types';
|
||||
|
||||
export function SeasonPage() {
|
||||
const { entryId, seasonId } = useParams<{
|
||||
@@ -20,15 +19,9 @@ export function SeasonPage() {
|
||||
}>();
|
||||
const { data: season, isLoading } = useSeason(parseInt(seasonId!, 10));
|
||||
const { data: episodes = [] } = useSeasonEpisodes(parseInt(seasonId!, 10));
|
||||
const createEpisodeSeen = useCreateEpisodeSeen();
|
||||
const entryTitle = useLibraryStore((s) => s.entries.get(parseInt(entryId!, 10))?.title);
|
||||
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 [markAllAccuracy, setMarkAllAccuracy] = useState<SeenAccuracy>('EXACT');
|
||||
const [showMarkAllConfirm, setShowMarkAllConfirm] = useState(false);
|
||||
|
||||
if (isLoading || !season) {
|
||||
return (
|
||||
@@ -78,18 +71,15 @@ export function SeasonPage() {
|
||||
<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>
|
||||
)}
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="shrink-0"
|
||||
onClick={() => setShowMarkAllDialog(true)}
|
||||
>
|
||||
<ListChecks className="mr-1.5 h-4 w-4" />
|
||||
Mark Season Watched
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<span>Season {season.season_number}</span>
|
||||
@@ -209,53 +199,13 @@ export function SeasonPage() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 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, accuracy) => {
|
||||
setMarkAllDate(date);
|
||||
setMarkAllSeenWith(seenWith);
|
||||
setMarkAllAccuracy(accuracy);
|
||||
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,
|
||||
accuracy: markAllAccuracy,
|
||||
season_id: parseInt(seasonId!, 10),
|
||||
});
|
||||
}
|
||||
setMarkingAll(false);
|
||||
setShowMarkAllConfirm(false);
|
||||
}}
|
||||
{/* Mark Season Watched dialog */}
|
||||
<MarkSeasonWatchedDialog
|
||||
open={showMarkAllDialog}
|
||||
onOpenChange={setShowMarkAllDialog}
|
||||
entryId={parseInt(entryId!, 10)}
|
||||
seasonId={parseInt(seasonId!, 10)}
|
||||
episodes={episodes}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user