From 1d2224e9410fa2cd68bc6d151d9861726b6a2b4e Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Wed, 17 Jul 2024 16:28:58 +0200 Subject: [PATCH] Add filter to learning path list view, refactor code --- .../LearningPathListTopic.vue | 37 +++++++++++ .../learningPathPage/LearningPathListView.vue | 21 +++---- .../learningPathPage/LearningPathPage.vue | 1 + .../LearningPathPathTopic.vue | 63 +++++++++++++++++++ .../learningPathPage/LearningPathPathView.vue | 58 ++++------------- client/tailwind.css | 5 +- 6 files changed, 123 insertions(+), 62 deletions(-) create mode 100644 client/src/pages/learningPath/learningPathPage/LearningPathListTopic.vue create mode 100644 client/src/pages/learningPath/learningPathPage/LearningPathPathTopic.vue diff --git a/client/src/pages/learningPath/learningPathPage/LearningPathListTopic.vue b/client/src/pages/learningPath/learningPathPage/LearningPathListTopic.vue new file mode 100644 index 00000000..9921976a --- /dev/null +++ b/client/src/pages/learningPath/learningPathPage/LearningPathListTopic.vue @@ -0,0 +1,37 @@ + + + diff --git a/client/src/pages/learningPath/learningPathPage/LearningPathListView.vue b/client/src/pages/learningPath/learningPathPage/LearningPathListView.vue index 3fe62231..e4f6fd56 100644 --- a/client/src/pages/learningPath/learningPathPage/LearningPathListView.vue +++ b/client/src/pages/learningPath/learningPathPage/LearningPathListView.vue @@ -1,26 +1,23 @@ diff --git a/client/src/pages/learningPath/learningPathPage/LearningPathPage.vue b/client/src/pages/learningPath/learningPathPage/LearningPathPage.vue index 093ba280..7af5a9b3 100644 --- a/client/src/pages/learningPath/learningPathPage/LearningPathPage.vue +++ b/client/src/pages/learningPath/learningPathPage/LearningPathPage.vue @@ -152,6 +152,7 @@ const changeViewType = (viewType: ViewType) => {
+import {computed} from "vue"; +import type { LearningContentWithCompletion, TopicType } from '@/types'; +import LearningPathCircleColumn from './LearningPathCircleColumn.vue'; + +interface Props { + topic: TopicType; + topicIndex: number; + nextLearningContent?: LearningContentWithCompletion; + overrideCircleUrlBase?: string; + filter?: string; + isLastTopic: boolean; +} + +const props = defineProps(); + +const isFirstCircle = (circleIndex: number) => + props.topicIndex === 0 && circleIndex === 0; + +const isLastCircle = (circleIndex: number, numCircles: number) => + props.isLastTopic && circleIndex === numCircles - 1; + + +const filteredCircles = computed(() => { + if (props.filter === undefined || props.filter === "") { + return props.topic.circles; + } + return props.topic.circles.filter( + (circle) => + circle.profiles.indexOf(props.filter as string) > -1 || circle.is_base_circle + ); +}); + + + diff --git a/client/src/pages/learningPath/learningPathPage/LearningPathPathView.vue b/client/src/pages/learningPath/learningPathPage/LearningPathPathView.vue index 1eb7e0ba..58068ba8 100644 --- a/client/src/pages/learningPath/learningPathPage/LearningPathPathView.vue +++ b/client/src/pages/learningPath/learningPathPage/LearningPathPathView.vue @@ -2,13 +2,13 @@ import LearningPathCircleColumn from "@/pages/learningPath/learningPathPage/LearningPathCircleColumn.vue"; import LearningPathScrollButton from "@/pages/learningPath/learningPathPage/LearningPathScrollButton.vue"; import { useScroll } from "@vueuse/core"; -import { nextTick, ref, watch } from "vue"; +import { computed, nextTick, ref, watch } from "vue"; import type { LearningContentWithCompletion, LearningPathType, - TopicType, } from "@/types"; import LoadingSpinner from "@/components/ui/LoadingSpinner.vue"; +import LearningPathPathTopic from "./LearningPathPathTopic.vue"; const props = defineProps<{ learningPath: LearningPathType | undefined; @@ -24,13 +24,6 @@ const scrollIncrement = 600; const learnPathDiagram = ref(null); const { x, arrivedState } = useScroll(learnPathDiagram, { behavior: "smooth" }); -const isFirstCircle = (topicIndex: number, circleIndex: number) => - topicIndex === 0 && circleIndex === 0; - -const isLastCircle = (topicIndex: number, circleIndex: number, numCircles: number) => - topicIndex === (props.learningPath?.topics ?? []).length - 1 && - circleIndex === numCircles - 1; - const scrollRight = () => scrollLearnPathDiagram(scrollIncrement); const scrollLeft = () => scrollLearnPathDiagram(-scrollIncrement); @@ -39,15 +32,7 @@ const scrollLearnPathDiagram = (offset: number) => { x.value += offset; }; -const filterCircles = (topic: TopicType) => { - if (props.filter === undefined || props.filter === "") { - return topic.circles; - } - return topic.circles.filter( - (circle) => - circle.profiles.indexOf(props.filter as string) > -1 || circle.is_base_circle - ); -}; +const topics = computed(() => props.learningPath?.topics ?? []); watch(()=> props.filter, () => { // we need to update the scroll state of the element, otherwise the arrows won't match the scroll state @@ -76,37 +61,16 @@ watch(()=> props.filter, () => { ref="learnPathDiagram" class="no-scrollbar flex h-96 snap-x flex-row overflow-auto py-5 sm:py-10" > -
-

- {{ topic.title }} -

-
- -
-
+ :topic-index="topicIndex" + :topic="topic" + :next-learning-content="nextLearningContent" + :override-circle-url-base="overrideCircleUrlBase" + :filter="filter" + :is-last-topic="topicIndex === (topics.length - 1)" + />