mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user