fix: throttle request issue per video,audio as indicated requirements in units and lessons

Signed-off-by: rgrgogu <obsequio.rus@gmail.com>
This commit is contained in:
rgrgogu
2026-07-15 17:00:46 +08:00
parent 5a9c0390e6
commit 35fb6a3544
9 changed files with 125 additions and 24 deletions
+35
View File
@@ -160,6 +160,40 @@ export function ClientLibraryProvider({ children }) {
}
}, []);
// Reports watch/listen playback progress for watch_percent / watch_video / listen_audio
// completion requirements — safe to call unconditionally for any standalone lesson (the
// backend no-ops when none of those types is configured on it). Fires frequently while
// playback is running (throttled ~3s by the block itself), so failures are swallowed
// rather than toasted — the next tick, or onEnded's final 100% call, catches up.
const upsertWatchProgress = useCallback(async (lessonUuid, unitUuid, percent, meta = {}) => {
try {
const { data } = await api.post(`/client/lessons/${lessonUuid}/watch-progress`, {
percent,
...(unitUuid ? { unit_uuid: unitUuid } : {}),
...(meta.blockId ? { block_id: meta.blockId } : {}),
...(meta.blockType ? { block_type: meta.blockType } : {}),
});
const result = data.data ?? null;
const cascadeLesson = result?.cascade?.lesson;
const cascadeUnit = result?.cascade?.unit;
setUnitDetail((prev) => {
if (!prev || !cascadeLesson) return prev;
const nextLessons = prev.lessons.map((l) =>
l.lesson_id === cascadeLesson.lesson_id
? { ...l, status: cascadeLesson.status }
: l
);
const is_completed = cascadeUnit ? cascadeUnit.status === "completed" : prev.is_completed;
return { ...prev, lessons: nextLessons, is_completed };
});
return result;
} catch {
return null;
}
}, []);
// ─── Resets ─────────────────────────────────────────────────────────────
const resetUnitDetail = useCallback(() => {
@@ -187,6 +221,7 @@ export function ClientLibraryProvider({ children }) {
submitUnitQuiz,
saveUnitQuizDraft,
upsertLessonProgress,
upsertWatchProgress,
resetUnitDetail,
resetLesson,