From 59c695b838d5b2dfb5e4353b4f681c95ccb9e94f Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Mon, 15 Jul 2024 16:42:28 +0200 Subject: [PATCH] Display chosen profile on user profile page --- client/src/gql/schema.graphql | 3 +- client/src/graphql/queries.ts | 4 +-- .../userProfile/LearningPathProfilePage.vue | 28 ++++++++++++++++++- server/vbv_lernwelt/course/graphql/types.py | 13 +++++++-- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/client/src/gql/schema.graphql b/client/src/gql/schema.graphql index 53a7aeb7..b3165147 100644 --- a/client/src/gql/schema.graphql +++ b/client/src/gql/schema.graphql @@ -267,7 +267,8 @@ type CourseObjectType { learning_path: LearningPathObjectType! action_competences: [ActionCompetenceObjectType!]! profiles: [String] - course_session_users: [CourseSessionUserType]! + course_session_users(id: String): [CourseSessionUserType]! + chosen_profile(user: String!): String } type ActionCompetenceObjectType implements CoursePageInterface { diff --git a/client/src/graphql/queries.ts b/client/src/graphql/queries.ts index f286ca75..95386f4d 100644 --- a/client/src/graphql/queries.ts +++ b/client/src/graphql/queries.ts @@ -264,14 +264,14 @@ export const COURSE_SESSION_DETAIL_QUERY = graphql(` `); export const COURSE_QUERY = graphql(` - query courseQuery($slug: String!) { + query courseQuery($slug: String!, $user: String) { course(slug: $slug) { id title slug category_name profiles - course_session_users { + course_session_users(id: $user) { id __typename chosen_profile diff --git a/client/src/pages/userProfile/LearningPathProfilePage.vue b/client/src/pages/userProfile/LearningPathProfilePage.vue index 34413b25..6517a2fb 100644 --- a/client/src/pages/userProfile/LearningPathProfilePage.vue +++ b/client/src/pages/userProfile/LearningPathProfilePage.vue @@ -4,8 +4,10 @@ import { useCourseDataWithCompletion } from "@/composables"; import UserProfileContent from "@/components/userProfile/UserProfileContent.vue"; import LearningPathCircle from "@/pages/learningPath/learningPathPage/LearningPathCircle.vue"; import LearningSequence from "@/pages/learningPath/circlePage/LearningSequence.vue"; -import { ref, watch } from "vue"; +import { computed, ref, watch } from "vue"; import type { CircleType } from "@/types"; +import { COURSE_QUERY } from "@/graphql/queries"; +import { useQuery } from "@urql/vue"; const props = defineProps<{ userId: string; @@ -20,6 +22,23 @@ function selectCircle(circle: CircleType) { selectedCircle.value = circle; } +const courseReactiveResult = useQuery({ + query: COURSE_QUERY, + variables: { slug: props.courseSlug, user: props.userId }, +}); + +const courseReactive = computed(() => courseReactiveResult.data.value?.course); +const courseSessionUsers = computed(() => { + return courseReactive.value?.course_session_users; +}); + +const chosenProfile = computed(() => { + if (courseSessionUsers.value && courseSessionUsers.value.length > 0) { + return courseSessionUsers.value[0]?.chosen_profile; + } + return null; +}); + watch(lpQueryResult.learningPath, () => { if (lpQueryResult.learningPath?.value?.topics?.length) { selectCircle(lpQueryResult.learningPath.value.topics[0].circles[0]); @@ -30,6 +49,13 @@ watch(lpQueryResult.learningPath, () => {