diff --git a/client/src/services/learningPath.ts b/client/src/services/learningPath.ts index be7c3df1..6d393340 100644 --- a/client/src/services/learningPath.ts +++ b/client/src/services/learningPath.ts @@ -10,8 +10,6 @@ import type { Topic, WagtailLearningPath, } from "@/types"; -import eventBus from "@/utils/eventBus"; -import log from "loglevel"; export interface ContinueData { url: string; @@ -100,14 +98,6 @@ export class LearningPath implements WagtailLearningPath { if (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() { diff --git a/client/src/stores/learningPath.ts b/client/src/stores/learningPath.ts index c186d6df..48b68e37 100644 --- a/client/src/stores/learningPath.ts +++ b/client/src/stores/learningPath.ts @@ -4,7 +4,9 @@ import { useCompletionStore } from "@/stores/completion"; import { useCourseSessionsStore } from "@/stores/courseSessions"; import { useUserStore } from "@/stores/user"; import type { CourseCompletion } from "@/types"; +import eventBus from "@/utils/eventBus"; import cloneDeep from "lodash/cloneDeep"; +import log from "loglevel"; import { defineStore } from "pinia"; import { computed, reactive } from "vue"; @@ -97,5 +99,18 @@ export const useLearningPathStore = defineStore("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 }; });