fix(frontend): Typeringsproblemen opgelost.
This commit is contained in:
parent
4d98be78c1
commit
ed8b5c919d
9 changed files with 30 additions and 22 deletions
|
@ -1,9 +1,10 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import ThemeCard from "@/components/ThemeCard.vue";
|
import ThemeCard from "@/components/ThemeCard.vue";
|
||||||
import { ref, watchEffect, computed } from "vue";
|
import {ref, watchEffect, computed, type Ref} from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { AGE_TO_THEMES, THEMESITEMS } from "@/utils/constants.ts";
|
import { AGE_TO_THEMES, THEMESITEMS } from "@/utils/constants.ts";
|
||||||
import { useThemeQuery } from "@/queries/themes.ts";
|
import { useThemeQuery } from "@/queries/themes.ts";
|
||||||
|
import type {Theme} from "@/data-objects/theme.ts";
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
selectedTheme: { type: String, required: true },
|
selectedTheme: { type: String, required: true },
|
||||||
|
@ -15,11 +16,11 @@
|
||||||
|
|
||||||
const { data: allThemes, isLoading, error } = useThemeQuery(language);
|
const { data: allThemes, isLoading, error } = useThemeQuery(language);
|
||||||
|
|
||||||
const allCards = ref([]);
|
const allCards: Ref<Theme[]> = ref([]);
|
||||||
const cards = ref([]);
|
const cards: Ref<Theme[]> = ref([]);
|
||||||
|
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
const themes = allThemes.value ?? [];
|
const themes: Theme[] = allThemes.value ?? [];
|
||||||
allCards.value = themes;
|
allCards.value = themes;
|
||||||
|
|
||||||
if (props.selectedTheme) {
|
if (props.selectedTheme) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ const props = defineProps<{learningPaths: LearningPath[]}>();
|
||||||
class="learning-path-card"
|
class="learning-path-card"
|
||||||
link
|
link
|
||||||
:to="`/learningPath/${learningPath.hruid}/${learningPath.language}/${learningPath.startNode.learningobjectHruid}`"
|
:to="`/learningPath/${learningPath.hruid}/${learningPath.language}/${learningPath.startNode.learningobjectHruid}`"
|
||||||
:key="[learningPath.hruid, learningPath.language]"
|
:key="`${learningPath.hruid}/${learningPath.language}`"
|
||||||
v-for="learningPath in props.learningPaths"
|
v-for="learningPath in props.learningPaths"
|
||||||
>
|
>
|
||||||
<v-img
|
<v-img
|
||||||
|
|
8
frontend/src/data-objects/theme.ts
Normal file
8
frontend/src/data-objects/theme.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
export interface Theme {
|
||||||
|
key: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
|
||||||
|
// URL of the image
|
||||||
|
image: string;
|
||||||
|
}
|
|
@ -39,13 +39,13 @@ export function useLearningObjectHTMLQuery(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useLearningObjectListForPathQuery(
|
export function useLearningObjectListForPathQuery(
|
||||||
learningPath: MaybeRefOrGetter<LearningPath>
|
learningPath: MaybeRefOrGetter<LearningPath | undefined>
|
||||||
): UseQueryReturnType<LearningObject, Error> {
|
): UseQueryReturnType<LearningObject[], Error> {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: [LEARNING_OBJECT_KEY, "onPath", learningPath],
|
queryKey: [LEARNING_OBJECT_KEY, "onPath", learningPath],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const learningObjects = [];
|
const learningObjects: Promise<LearningObject>[] = [];
|
||||||
for (const node of toValue(learningPath).nodesAsList) {
|
for (const node of toValue(learningPath)!.nodesAsList) {
|
||||||
learningObjects.push(
|
learningObjects.push(
|
||||||
learningObjectController.getMetadata(node.learningobjectHruid, node.language, node.version)
|
learningObjectController.getMetadata(node.learningobjectHruid, node.language, node.version)
|
||||||
);
|
);
|
||||||
|
|
|
@ -33,12 +33,12 @@ export function useGetAllLearningPathsByThemeQuery(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSearchLearningPathQuery(
|
export function useSearchLearningPathQuery(
|
||||||
query: MaybeRefOrGetter<string>
|
query: MaybeRefOrGetter<string | undefined>
|
||||||
): UseQueryReturnType<LearningPath[], Error> {
|
): UseQueryReturnType<LearningPath[], Error> {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: [LEARNING_PATH_KEY, "search", query],
|
queryKey: [LEARNING_PATH_KEY, "search", query],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const queryVal = toValue(query);
|
const queryVal = toValue(query)!;
|
||||||
return learningPathController.search(queryVal);
|
return learningPathController.search(queryVal);
|
||||||
},
|
},
|
||||||
enabled: () => Boolean(toValue(query)),
|
enabled: () => Boolean(toValue(query)),
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import { useQuery, type UseQueryReturnType } from "@tanstack/vue-query";
|
import { useQuery, type UseQueryReturnType } from "@tanstack/vue-query";
|
||||||
import { getThemeController } from "@/controllers/controllers";
|
import { getThemeController } from "@/controllers/controllers";
|
||||||
import { type MaybeRefOrGetter, toValue } from "vue";
|
import { type MaybeRefOrGetter, toValue } from "vue";
|
||||||
|
import type {Theme} from "@/data-objects/theme.ts";
|
||||||
|
|
||||||
const themeController = getThemeController();
|
const themeController = getThemeController();
|
||||||
|
|
||||||
export function useThemeQuery(language: MaybeRefOrGetter<string>): UseQueryReturnType<unknown, Error> {
|
export function useThemeQuery(language: MaybeRefOrGetter<string>): UseQueryReturnType<Theme[], Error> {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["themes", language],
|
queryKey: ["themes", language],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
|
|
@ -14,9 +14,7 @@ const language = computed(() => locale.value);
|
||||||
|
|
||||||
const themeQueryResult = useThemeQuery(language);
|
const themeQueryResult = useThemeQuery(language);
|
||||||
|
|
||||||
const currentThemeInfo = computed(() =>
|
const currentThemeInfo = computed(() => themeQueryResult.data.value?.find(it => it.key === props.theme));
|
||||||
themeQueryResult.isSuccess.value ? themeQueryResult.data.value.filter(it => it.key === props.theme)[0] : undefined
|
|
||||||
);
|
|
||||||
|
|
||||||
const learningPathsForThemeQueryResult = useGetAllLearningPathsByThemeQuery(() => props.theme);
|
const learningPathsForThemeQueryResult = useGetAllLearningPathsByThemeQuery(() => props.theme);
|
||||||
|
|
||||||
|
@ -26,7 +24,7 @@ const searchFilter = ref("");
|
||||||
function filterLearningPaths(learningPaths: LearningPath[]): LearningPath[] {
|
function filterLearningPaths(learningPaths: LearningPath[]): LearningPath[] {
|
||||||
return learningPaths.filter(it =>
|
return learningPaths.filter(it =>
|
||||||
it.title.toLowerCase().includes(searchFilter.value.toLowerCase())
|
it.title.toLowerCase().includes(searchFilter.value.toLowerCase())
|
||||||
|| it.description.toLowerCase().includes(searchFilter.value.toLowerCase)
|
|| it.description.toLowerCase().includes(searchFilter.value.toLowerCase())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +33,8 @@ function filterLearningPaths(learningPaths: LearningPath[]): LearningPath[] {
|
||||||
<template>
|
<template>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<using-query-result :query-result="themeQueryResult">
|
<using-query-result :query-result="themeQueryResult">
|
||||||
<h1>{{ currentThemeInfo.title }}</h1>
|
<h1>{{ currentThemeInfo!!.title }}</h1>
|
||||||
<p>{{ currentThemeInfo.description }}</p>
|
<p>{{ currentThemeInfo!!.description }}</p>
|
||||||
<div class="search-field-container">
|
<div class="search-field-container">
|
||||||
<v-text-field
|
<v-text-field
|
||||||
class="search-field"
|
class="search-field"
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
const learningObjectListQueryResult = useLearningObjectListForPathQuery(learningPathQueryResult.data);
|
const learningObjectListQueryResult = useLearningObjectListForPathQuery(learningPathQueryResult.data);
|
||||||
|
|
||||||
const nodesList: ComputedRef<LearningPathNode[] | null> = computed(() =>
|
const nodesList: ComputedRef<LearningPathNode[] | null> = computed(() =>
|
||||||
learningPathQueryResult.isSuccess ? learningPathQueryResult.data.value?.nodesAsList : null
|
learningPathQueryResult.data.value?.nodesAsList ?? null
|
||||||
);
|
);
|
||||||
|
|
||||||
const currentNode = computed(() => {
|
const currentNode = computed(() => {
|
||||||
|
@ -71,11 +71,11 @@
|
||||||
|
|
||||||
function isLearningObjectCompleted(learningObject: LearningObject): boolean {
|
function isLearningObjectCompleted(learningObject: LearningObject): boolean {
|
||||||
if (learningObjectListQueryResult.isSuccess) {
|
if (learningObjectListQueryResult.isSuccess) {
|
||||||
return learningPathQueryResult.data.value.nodesAsList.find(it =>
|
return learningPathQueryResult.data.value?.nodesAsList?.find(it =>
|
||||||
it.learningobjectHruid === learningObject.key
|
it.learningobjectHruid === learningObject.key
|
||||||
&& it.version === learningObject.version
|
&& it.version === learningObject.version
|
||||||
&& it.language === learningObject.language
|
&& it.language === learningObject.language
|
||||||
).done;
|
)?.done ?? false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
const query = computed(() => route.query.query as string | null);
|
const query = computed(() => route.query.query as string | undefined);
|
||||||
|
|
||||||
const searchQueryResults = useSearchLearningPathQuery(query);
|
const searchQueryResults = useSearchLearningPathQuery(query);
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue