refactor(backend): LearningPathPage en LearningObjectView gerefactored, zodat ze TanStack gebruiken.
This commit is contained in:
parent
61fd28e743
commit
c6ee22ab4d
3 changed files with 32 additions and 52 deletions
|
@ -1,23 +1,19 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {Language} from "@/services/learning-content/language.ts";
|
import {Language} from "@/data-objects/language.ts";
|
||||||
import {watch} from "vue";
|
import {type UseQueryReturnType} from "@tanstack/vue-query";
|
||||||
import {getLearningObjectHTML} from "@/services/learning-content/learning-object-service.ts";
|
import {useLearningObjectHTMLQuery} from "@/queries/learning-objects.ts";
|
||||||
import UsingRemoteResource from "@/components/UsingRemoteResource.vue";
|
import UsingQueryResult from "@/components/UsingQueryResult.vue";
|
||||||
import {loadResource, remoteResource} from "@/services/api-client/remote-resource.ts";
|
|
||||||
|
|
||||||
const props = defineProps<{hruid: string, language: Language, version: number}>()
|
const props = defineProps<{hruid: string, language: Language, version: number}>()
|
||||||
|
|
||||||
const learningPathHtmlResource = remoteResource<Document>();
|
const learningObjectHtmlQueryResult: UseQueryReturnType<Document, Error> = useLearningObjectHTMLQuery(props.hruid, props.language, props.version);
|
||||||
watch(props, () => {
|
|
||||||
loadResource(learningPathHtmlResource, getLearningObjectHTML(props.hruid, props.language, props.version))
|
|
||||||
}, {immediate: true});
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<using-remote-resource :resource="learningPathHtmlResource" v-slot="learningPathHtml : {data: Document}">
|
<using-query-result :query-result="learningObjectHtmlQueryResult as UseQueryReturnType<Document, Error>" v-slot="learningPathHtml : {data: Document}">
|
||||||
<div class="learning-object-container" v-html="learningPathHtml.data.body.innerHTML"></div>
|
<div class="learning-object-container" v-html="learningPathHtml.data.body.innerHTML"></div>
|
||||||
</using-remote-resource>
|
</using-query-result>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {Language} from "@/services/learning-content/language.ts";
|
import {Language} from "@/data-objects/language.ts";
|
||||||
import {getLearningPath} from "@/services/learning-content/learning-path-service.ts";
|
import {type LearningPath, LearningPathNode} from "@/data-objects/learning-path.ts";
|
||||||
import UsingRemoteResource from "@/components/UsingRemoteResource.vue";
|
|
||||||
import {type LearningPath, LearningPathNode} from "@/services/learning-content/learning-path.ts";
|
|
||||||
import {computed, type ComputedRef, ref, watch} from "vue";
|
import {computed, type ComputedRef, ref, watch} from "vue";
|
||||||
import type {LearningObject} from "@/services/learning-content/learning-object.ts";
|
import type {LearningObject} from "@/data-objects/learning-object.ts";
|
||||||
import {useRoute, useRouter} from "vue-router";
|
import {useRoute, useRouter} from "vue-router";
|
||||||
import {loadResource, remoteResource, type SuccessState} from "@/services/api-client/remote-resource.ts";
|
import {type SuccessState} from "@/services/api-client/remote-resource.ts";
|
||||||
import LearningObjectView from "@/views/learning-paths/LearningObjectView.vue";
|
import LearningObjectView from "@/views/learning-paths/LearningObjectView.vue";
|
||||||
import {useI18n} from "vue-i18n";
|
import {useI18n} from "vue-i18n";
|
||||||
import LearningPathSearchField from "@/components/LearningPathSearchField.vue";
|
import LearningPathSearchField from "@/components/LearningPathSearchField.vue";
|
||||||
|
import {useGetLearningPathQuery} from "@/queries/learning-paths.ts";
|
||||||
|
import {useLearningObjectListForPathQuery} from "@/queries/learning-objects.ts";
|
||||||
|
import UsingQueryResult from "@/components/UsingQueryResult.vue";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
@ -22,32 +23,15 @@
|
||||||
forGroup?: string
|
forGroup?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const learningPathResource = remoteResource<LearningPath>();
|
const typedQuery = computed(() => route.query as QueryParams)
|
||||||
watch([() => props.hruid, () => props.language, () => route.query.forStudent, () => route.query.forGroup], () => {
|
|
||||||
loadResource(
|
|
||||||
learningPathResource,
|
|
||||||
getLearningPath(
|
|
||||||
props.hruid,
|
|
||||||
props.language,
|
|
||||||
route.query as QueryParams
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}, {immediate: true});
|
|
||||||
|
|
||||||
const learningObjectListResource = remoteResource<LearningObject[]>();
|
const learningPathQueryResult = useGetLearningPathQuery(props.hruid, props.language, typedQuery.value);
|
||||||
watch(learningPathResource, () => {
|
|
||||||
if (learningPathResource.state.type === "success") {
|
|
||||||
loadResource(learningObjectListResource, learningPathResource.state.data.learningObjectsAsList)
|
|
||||||
}
|
|
||||||
}, {immediate: true});
|
|
||||||
|
|
||||||
const nodesList: ComputedRef<LearningPathNode[] | null> = computed(() => {
|
const learningObjectListQueryResult = useLearningObjectListForPathQuery(learningPathQueryResult.data.value);
|
||||||
if (learningPathResource.state.type === "success") {
|
|
||||||
return learningPathResource.state.data.nodesAsList;
|
const nodesList: ComputedRef<LearningPathNode[] | null> = computed(() =>
|
||||||
} else {
|
(!learningPathQueryResult.isPending && !learningPathQueryResult.isError) ? learningPathQueryResult.data.value?.nodesAsList : null
|
||||||
return null;
|
);
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const currentNode = computed(() => {
|
const currentNode = computed(() => {
|
||||||
const currentHruid = props.learningObjectHruid;
|
const currentHruid = props.learningObjectHruid;
|
||||||
|
@ -74,8 +58,8 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(() => learningPathResource.state, (newValue) => {
|
watch(() => learningPathQueryResult, (newValue) => {
|
||||||
if (!props.learningObjectHruid && newValue.type === "success") {
|
if (learningPathQueryResult.isSuccess && false) {
|
||||||
router.push({
|
router.push({
|
||||||
path: router.currentRoute.value.path + "/" + (newValue as SuccessState<LearningPath>).data.startNode.learningobjectHruid,
|
path: router.currentRoute.value.path + "/" + (newValue as SuccessState<LearningPath>).data.startNode.learningobjectHruid,
|
||||||
query: route.query,
|
query: route.query,
|
||||||
|
@ -87,8 +71,8 @@
|
||||||
|
|
||||||
|
|
||||||
function isLearningObjectCompleted(learningObject: LearningObject): boolean {
|
function isLearningObjectCompleted(learningObject: LearningObject): boolean {
|
||||||
if (learningPathResource.state.type === "success") {
|
if (learningObjectListQueryResult.isSuccess) {
|
||||||
return learningPathResource.state.data.nodesAsList.filter(it =>
|
return learningPathQueryResult.data.value.nodesAsList.filter(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
|
||||||
|
@ -124,8 +108,8 @@
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<v-main>
|
<v-main>
|
||||||
<using-remote-resource
|
<using-query-result
|
||||||
:resource="learningPathResource"
|
:query-result="learningPathQueryResult"
|
||||||
v-slot="learningPath: {data: LearningPath}"
|
v-slot="learningPath: {data: LearningPath}"
|
||||||
>
|
>
|
||||||
<v-navigation-drawer v-model="navigationDrawerShown">
|
<v-navigation-drawer v-model="navigationDrawerShown">
|
||||||
|
@ -143,8 +127,8 @@
|
||||||
<v-divider></v-divider>
|
<v-divider></v-divider>
|
||||||
|
|
||||||
<div v-if="props.learningObjectHruid">
|
<div v-if="props.learningObjectHruid">
|
||||||
<using-remote-resource
|
<using-query-result
|
||||||
:resource="learningObjectListResource"
|
:query-result="learningObjectListQueryResult"
|
||||||
v-slot="learningObjects: {data: LearningObject[]}"
|
v-slot="learningObjects: {data: LearningObject[]}"
|
||||||
>
|
>
|
||||||
<v-list-item
|
<v-list-item
|
||||||
|
@ -163,7 +147,7 @@
|
||||||
{{ node.estimatedTime }}'
|
{{ node.estimatedTime }}'
|
||||||
</template>
|
</template>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
</using-remote-resource>
|
</using-query-result>
|
||||||
</div>
|
</div>
|
||||||
</v-navigation-drawer>
|
</v-navigation-drawer>
|
||||||
<div class="control-bar-above-content">
|
<div class="control-bar-above-content">
|
||||||
|
@ -201,7 +185,7 @@
|
||||||
{{ t("next") }}
|
{{ t("next") }}
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</div>
|
</div>
|
||||||
</using-remote-resource>
|
</using-query-result>
|
||||||
</v-main>
|
</v-main>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {loadResource, remoteResource} from "@/services/api-client/remote-resource.ts";
|
import {loadResource, remoteResource} from "@/services/api-client/remote-resource.ts";
|
||||||
import type {LearningPath} from "@/services/learning-content/learning-path.ts";
|
import type {LearningPath} from "@/data-objects/learning-path.ts";
|
||||||
import {useRoute, useRouter} from "vue-router";
|
import {useRoute, useRouter} from "vue-router";
|
||||||
import {computed, watch} from "vue";
|
import {computed, watch} from "vue";
|
||||||
import {searchLearningPaths} from "@/services/learning-content/learning-path-service.ts";
|
import {searchLearningPaths} from "@/services/learning-content/learning-path-service.ts";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue