diff --git a/client/src/App.vue b/client/src/App.vue index ad7b919b..1e6b0e63 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -30,8 +30,10 @@ onMounted(() => { log.debug("App mounted"); eventBus.on("switchedCourseSession", () => { - // FIXME: clean up with VBV-305 + // Rerender the component tree, when the course session gets switched. + // So that the current learning path completion data gets updated. componentKey.value++; + log.info("Switched course session, re-evaluate component tree"); }); }); diff --git a/client/src/composables.ts b/client/src/composables.ts index e69de29b..ffd1b590 100644 --- a/client/src/composables.ts +++ b/client/src/composables.ts @@ -0,0 +1,30 @@ +import { useCourseSessionsStore } from "@/stores/courseSessions"; +import type { CourseSession } from "@/types"; +import log from "loglevel"; +import type { ComputedRef } from "vue"; +import { computed } from "vue"; + +export function useCurrentCourseSession() { + /** + * We often need the current course session in our components. + * With this composable we can get it easily. + */ + const store = useCourseSessionsStore(); + + const result: ComputedRef = computed( + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + () => { + if (!store.currentCourseSession) { + log.error( + "currentCourseSession is only defined in pages with :courseSlug in the route" + ); + throw new Error( + `currentCourseSession is not defined in the store. + It is only defined in pages with :courseSlug in the route` + ); + } + return store.currentCourseSession; + } + ); + return result; +} diff --git a/client/src/pages/cockpit/CockpitParentPage.vue b/client/src/pages/cockpit/CockpitParentPage.vue index 9a3882be..f39be69c 100644 --- a/client/src/pages/cockpit/CockpitParentPage.vue +++ b/client/src/pages/cockpit/CockpitParentPage.vue @@ -1,7 +1,7 @@