Skip to content

Commit

Permalink
Fetch lesson sizes before commiting new lessons
Browse files Browse the repository at this point in the history
so that they can be commited together with their sizes.

Fixes learningequality#10797
  • Loading branch information
MisRob committed Sep 2, 2023
1 parent 8423afd commit 44156af
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions kolibri/plugins/coach/assets/src/modules/lessonsRoot/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,37 @@ export function refreshClassLessons(store, classId) {
force: true,
})
.then(lessons => {
// Fetch lesson sizes before commiting new lessons
// so that they can be commited together with their sizes.
// Fixes https://github.com/learningequality/kolibri/issues/10797
if (Object.keys(lessons).length > 0) {
return store.dispatch('fetchLessonsSizes', classId, false).then(sizes => {
return { lessons, sizes };
});
} else {
return { lessons, sizes: null };
}
})
.then(({ lessons, sizes }) => {
store.commit('SET_CLASS_LESSONS', lessons);
if (sizes) {
store.commit('SET_CLASS_LESSONS_SIZES', sizes);
}
// resolve lessons in case it's needed
return lessons;
})
.then(lessons => {
if (Object.keys(lessons).length > 0) {
return store.dispatch('fetchLessonsSizes', classId);
}
})
.catch(error => {
return store.dispatch('handleApiError', { error }, { root: true });
});
}

export function fetchLessonsSizes(store, classId) {
export function fetchLessonsSizes(store, classId, shouldCommit = true) {
return LessonResource.fetchLessonsSizes({ collection: classId })
.then(sizes => {
store.commit('SET_CLASS_LESSONS_SIZES', sizes);
if (shouldCommit) {
store.commit('SET_CLASS_LESSONS_SIZES', sizes);
}
return sizes;
})
.catch(error => {
return store.dispatch('handleApiError', { error }, { root: true });
Expand Down

0 comments on commit 44156af

Please sign in to comment.