mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 06:15:39 -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(
|
const handleStatusChange = useCallback(
|
||||||
async (status: string | null) => {
|
async (status: string | null) => {
|
||||||
const prev = userStatus;
|
const prev = userStatus;
|
||||||
|
const prevWatches = episodeWatches;
|
||||||
setUserStatus(status);
|
setUserStatus(status);
|
||||||
|
if (status === "completed" && titleType === "tv") {
|
||||||
|
const allEpIds = seasons.flatMap((s) => s.episodes.map((ep) => ep.id));
|
||||||
|
setEpisodeWatches(allEpIds);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await updateTitleStatus(titleId, status);
|
await updateTitleStatus(titleId, status);
|
||||||
const label =
|
const label =
|
||||||
@@ -95,10 +100,11 @@ export function TitleInteractionProvider({
|
|||||||
toast.success(label);
|
toast.success(label);
|
||||||
} catch {
|
} catch {
|
||||||
setUserStatus(prev);
|
setUserStatus(prev);
|
||||||
|
setEpisodeWatches(prevWatches);
|
||||||
toast.error("Failed to update status");
|
toast.error("Failed to update status");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[titleId, userStatus],
|
[titleId, titleType, userStatus, episodeWatches, seasons],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleRating = useCallback(
|
const handleRating = useCallback(
|
||||||
|
|||||||
Reference in New Issue
Block a user