diff --git a/client/src/components/learningPath/LearningPathDiagram.vue b/client/src/components/learningPath/LearningPathDiagram.vue index 3ba82e82..d3b52d5f 100644 --- a/client/src/components/learningPath/LearningPathDiagram.vue +++ b/client/src/components/learningPath/LearningPathDiagram.vue @@ -1,15 +1,15 @@ diff --git a/client/src/composables.ts b/client/src/composables.ts index 37a4812f..bf718430 100644 --- a/client/src/composables.ts +++ b/client/src/composables.ts @@ -1,5 +1,5 @@ import { COURSE_SESSION_DETAIL_QUERY, LEARNING_PATH_QUERY } from "@/graphql/queries"; -import { circleFlatChildren } from "@/services/circle"; +import { circleFlatChildren, circleFlatLearningContents } from "@/services/circle"; import { useCompletionStore } from "@/stores/completion"; import { useCourseSessionsStore } from "@/stores/courseSessions"; import { useUserStore } from "@/stores/user"; @@ -133,6 +133,10 @@ export function useCourseSessionDetailQuery(courSessionId?: string) { }; } +export function flatCircles(learningPath: LearningPathType) { + return learningPath.topics.flatMap((t) => t.circles); +} + export function useLearningPathQuery(courseSlug: string) { const queryResult = useQuery({ query: LEARNING_PATH_QUERY, @@ -147,7 +151,7 @@ export function useLearningPathQuery(courseSlug: string) { const circles = computed(() => { if (learningPath.value) { - return learningPath.value.topics.flatMap((t) => t.circles); + return flatCircles(learningPath.value); } return undefined; }); @@ -158,7 +162,20 @@ export function useLearningPathQuery(courseSlug: string) { }); } - return { ...queryResult, learningPath, circles, findCircle }; + const dataLoaded = ref(false); + + function waitForData() { + return new Promise((resolve) => { + watchEffect(() => { + if (queryResult.data.value) { + dataLoaded.value = true; + resolve(queryResult.data.value); + } + }); + }); + } + + return { ...queryResult, waitForData, learningPath, circles, findCircle }; } export function useLearningPathWithCompletion( @@ -178,6 +195,7 @@ export function useLearningPathWithCompletion( const lpQueryResult = useLearningPathQuery(courseSlug); const completionStore = useCompletionStore(); + const nextLearningContent = ref(null); function updateCompletionData() { if (userId && courseSessionId) { @@ -209,6 +227,13 @@ export function useLearningPathWithCompletion( }); }); } + + // FIXME calculate nextLearningContent + if (lpQueryResult.circles.value?.length) { + nextLearningContent.value = circleFlatLearningContents( + lpQueryResult.circles.value[0] + )[0]; + } } async function markCompletion( @@ -226,5 +251,10 @@ export function useLearningPathWithCompletion( } } - return { ...lpQueryResult, updateCompletionData, markCompletion }; + return { + ...lpQueryResult, + updateCompletionData, + markCompletion, + nextLearningContent, + }; } diff --git a/client/src/pages/DashboardPage.vue b/client/src/pages/DashboardPage.vue index 535246bc..c5f964bc 100644 --- a/client/src/pages/DashboardPage.vue +++ b/client/src/pages/DashboardPage.vue @@ -50,6 +50,7 @@ const getNextStepLink = (courseSession: CourseSession) => {
diff --git a/client/src/pages/learningPath/learningPathPage/LearningPathListView.vue b/client/src/pages/learningPath/learningPathPage/LearningPathListView.vue index 5e339dc1..a2c1bde3 100644 --- a/client/src/pages/learningPath/learningPathPage/LearningPathListView.vue +++ b/client/src/pages/learningPath/learningPathPage/LearningPathListView.vue @@ -1,11 +1,11 @@