Fix episodes not showing as watched when marking title completed

Optimistically update episodeWatches client state when setting status
to "completed" on a TV title, so episodes render as watched immediately
without requiring a page refresh.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-03 11:51:46 -05:00
co-authored by Claude Opus 4.6
parent ec256b7a96
commit 6f415ad0b2
@@ -81,7 +81,12 @@ export function TitleInteractionProvider({
const handleStatusChange = useCallback(
async (status: string | null) => {
const prev = userStatus;
const prevWatches = episodeWatches;
setUserStatus(status);
if (status === "completed" && titleType === "tv") {
const allEpIds = seasons.flatMap((s) => s.episodes.map((ep) => ep.id));
setEpisodeWatches(allEpIds);
}
try {
await updateTitleStatus(titleId, status);
const label =
@@ -95,10 +100,11 @@ export function TitleInteractionProvider({
toast.success(label);
} catch {
setUserStatus(prev);
setEpisodeWatches(prevWatches);
toast.error("Failed to update status");
}
},
[titleId, userStatus],
[titleId, titleType, userStatus, episodeWatches, seasons],
);
const handleRating = useCallback(