From 498b225cff776acd859f40a5e554e058903ea742 Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Mon, 7 Oct 2024 15:22:20 +0200 Subject: [PATCH 1/2] VBV-757: clone data from query --- client/src/composables.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/src/composables.ts b/client/src/composables.ts index 54c968bc..d8df4ac5 100644 --- a/client/src/composables.ts +++ b/client/src/composables.ts @@ -47,6 +47,7 @@ import type { import { useQuery } from "@urql/vue"; import dayjs from "dayjs"; import { t } from "i18next"; +import { cloneDeep } from "lodash"; import orderBy from "lodash/orderBy"; import log from "loglevel"; import type { ComputedRef, Ref } from "vue"; @@ -192,10 +193,10 @@ export function useCourseData(courseSlug: string) { log.error(result.error); } - course.value = result.data?.course as unknown as Course; - actionCompetences.value = result.data?.course - ?.action_competences as ActionCompetence[]; - learningPath.value = result.data?.course?.learning_path as LearningPathType; + const courseData = cloneDeep(result.data?.course) as Course; + course.value = courseData; + actionCompetences.value = courseData.action_competences as ActionCompetence[]; + learningPath.value = courseData.learning_path as LearningPathType; // attach circle information to learning contents if (learningPath.value) { From 81b20f2ce12871ba8c0f23be23dc8c4786c25181 Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Mon, 7 Oct 2024 16:50:55 +0200 Subject: [PATCH 2/2] Fix typecheck errors --- client/src/composables.ts | 4 +++- client/src/types.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/client/src/composables.ts b/client/src/composables.ts index d8df4ac5..32102146 100644 --- a/client/src/composables.ts +++ b/client/src/composables.ts @@ -193,7 +193,9 @@ export function useCourseData(courseSlug: string) { log.error(result.error); } - const courseData = cloneDeep(result.data?.course) as Course; + // VBV-757: clone data from `COURSE_QUERY` here, so that each user in + // `useCourseDataWithCompletion` has its own completion instance in the course + const courseData = cloneDeep(result.data?.course) as unknown as Course; course.value = courseData; actionCompetences.value = courseData.action_competences as ActionCompetence[]; learningPath.value = courseData.learning_path as LearningPathType; diff --git a/client/src/types.ts b/client/src/types.ts index 93ed9552..a24f6ecb 100644 --- a/client/src/types.ts +++ b/client/src/types.ts @@ -204,6 +204,8 @@ export interface Course { slug: string; profiles: string[]; configuration: CourseConfiguration; + learning_path?: LearningPathType; + action_competences?: ActionCompetence[]; } export interface CourseCategory {