Move learningPath completion data reloading code
This commit is contained in:
parent
a0f9e0dfee
commit
84ec0b9c53
|
|
@ -10,8 +10,6 @@ import type {
|
||||||
Topic,
|
Topic,
|
||||||
WagtailLearningPath,
|
WagtailLearningPath,
|
||||||
} from "@/types";
|
} from "@/types";
|
||||||
import eventBus from "@/utils/eventBus";
|
|
||||||
import log from "loglevel";
|
|
||||||
|
|
||||||
export interface ContinueData {
|
export interface ContinueData {
|
||||||
url: string;
|
url: string;
|
||||||
|
|
@ -100,14 +98,6 @@ export class LearningPath implements WagtailLearningPath {
|
||||||
if (completionData) {
|
if (completionData) {
|
||||||
this.calcNextLearningContent(completionData);
|
this.calcNextLearningContent(completionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userId) {
|
|
||||||
// TODO this might become a memory leak without unbinding...
|
|
||||||
eventBus.on("switchedCourseSession", (courseSession) => {
|
|
||||||
log.debug("handle switchedCourseSession", courseSession);
|
|
||||||
this.reloadCompletionData();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async reloadCompletionData() {
|
public async reloadCompletionData() {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@ import { useCompletionStore } from "@/stores/completion";
|
||||||
import { useCourseSessionsStore } from "@/stores/courseSessions";
|
import { useCourseSessionsStore } from "@/stores/courseSessions";
|
||||||
import { useUserStore } from "@/stores/user";
|
import { useUserStore } from "@/stores/user";
|
||||||
import type { CourseCompletion } from "@/types";
|
import type { CourseCompletion } from "@/types";
|
||||||
|
import eventBus from "@/utils/eventBus";
|
||||||
import cloneDeep from "lodash/cloneDeep";
|
import cloneDeep from "lodash/cloneDeep";
|
||||||
|
import log from "loglevel";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { computed, reactive } from "vue";
|
import { computed, reactive } from "vue";
|
||||||
|
|
||||||
|
|
@ -97,5 +99,18 @@ export const useLearningPathStore = defineStore("learningPath", () => {
|
||||||
return learningPath;
|
return learningPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reloadCompletionData() {
|
||||||
|
state.learningPaths.forEach((lp) => {
|
||||||
|
if (lp.userId) {
|
||||||
|
lp.reloadCompletionData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
eventBus.on("switchedCourseSession", (courseSession) => {
|
||||||
|
log.debug("handle switchedCourseSession", courseSession);
|
||||||
|
reloadCompletionData();
|
||||||
|
});
|
||||||
|
|
||||||
return { state, learningPathForUser, loadCompletionData, loadLearningPath };
|
return { state, learningPathForUser, loadCompletionData, loadLearningPath };
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue