mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 05:05:38 -04:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user