style: fix linting issues met Prettier
This commit is contained in:
parent
a65e95ac46
commit
1203f12ff4
33 changed files with 359 additions and 307 deletions
|
@ -1,30 +1,34 @@
|
|||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { computed, ref, watch, type Ref } from 'vue';
|
||||
import JsonEditorVue from 'json-editor-vue'
|
||||
import ButtonWithConfirmation from '@/components/ButtonWithConfirmation.vue'
|
||||
import { useDeleteLearningPathMutation, usePostLearningPathMutation, usePutLearningPathMutation } from '@/queries/learning-paths';
|
||||
import { Language } from '@/data-objects/language';
|
||||
import type { LearningPath } from '@dwengo-1/common/interfaces/learning-content';
|
||||
import type { AxiosError } from 'axios';
|
||||
import { parse } from 'uuid';
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { computed, ref, watch, type Ref } from "vue";
|
||||
import JsonEditorVue from "json-editor-vue";
|
||||
import ButtonWithConfirmation from "@/components/ButtonWithConfirmation.vue";
|
||||
import {
|
||||
useDeleteLearningPathMutation,
|
||||
usePostLearningPathMutation,
|
||||
usePutLearningPathMutation,
|
||||
} from "@/queries/learning-paths";
|
||||
import { Language } from "@/data-objects/language";
|
||||
import type { LearningPath } from "@dwengo-1/common/interfaces/learning-content";
|
||||
import type { AxiosError } from "axios";
|
||||
import { parse } from "uuid";
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const props = defineProps<{
|
||||
selectedLearningPath?: LearningPath
|
||||
selectedLearningPath?: LearningPath;
|
||||
}>();
|
||||
|
||||
const { isPending, mutate, error: deleteError, isSuccess: deleteSuccess } = useDeleteLearningPathMutation();
|
||||
|
||||
const DEFAULT_LEARNING_PATH: LearningPath = {
|
||||
language: 'en',
|
||||
hruid: '...',
|
||||
title: '...',
|
||||
description: '...',
|
||||
language: "en",
|
||||
hruid: "...",
|
||||
title: "...",
|
||||
description: "...",
|
||||
nodes: [
|
||||
{
|
||||
learningobject_hruid: '...',
|
||||
learningobject_hruid: "...",
|
||||
language: Language.English,
|
||||
version: 1,
|
||||
start_node: true,
|
||||
|
@ -33,17 +37,17 @@ import { parse } from 'uuid';
|
|||
default: true,
|
||||
condition: "(remove if the transition should be unconditinal)",
|
||||
next: {
|
||||
hruid: '...',
|
||||
hruid: "...",
|
||||
version: 1,
|
||||
language: '...'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
language: "...",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
keywords: 'Keywords separated by spaces',
|
||||
target_ages: []
|
||||
}
|
||||
keywords: "Keywords separated by spaces",
|
||||
target_ages: [],
|
||||
};
|
||||
|
||||
const { isPending: isPostPending, error: postError, mutate: doPost } = usePostLearningPathMutation();
|
||||
const { isPending: isPutPending, error: putError, mutate: doPut } = usePutLearningPathMutation();
|
||||
|
@ -51,11 +55,13 @@ import { parse } from 'uuid';
|
|||
const learningPath: Ref<LearningPath | string> = ref(DEFAULT_LEARNING_PATH);
|
||||
|
||||
const parsedLearningPath = computed(() =>
|
||||
typeof learningPath.value === "string" ? JSON.parse(learningPath.value) as LearningPath
|
||||
: learningPath.value
|
||||
typeof learningPath.value === "string" ? (JSON.parse(learningPath.value) as LearningPath) : learningPath.value,
|
||||
);
|
||||
|
||||
watch(() => props.selectedLearningPath, () => learningPath.value = props.selectedLearningPath ?? DEFAULT_LEARNING_PATH);
|
||||
watch(
|
||||
() => props.selectedLearningPath,
|
||||
() => (learningPath.value = props.selectedLearningPath ?? DEFAULT_LEARNING_PATH),
|
||||
);
|
||||
|
||||
function uploadLearningPath(): void {
|
||||
if (props.selectedLearningPath) {
|
||||
|
@ -69,20 +75,20 @@ import { parse } from 'uuid';
|
|||
if (props.selectedLearningPath) {
|
||||
mutate({
|
||||
hruid: props.selectedLearningPath.hruid,
|
||||
language: props.selectedLearningPath.language as Language
|
||||
language: props.selectedLearningPath.language as Language,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function extractErrorMessage(error: AxiosError): string {
|
||||
return (error.response?.data as {error: string}).error ?? error.message;
|
||||
return (error.response?.data as { error: string }).error ?? error.message;
|
||||
}
|
||||
|
||||
const isIdModified = computed(() =>
|
||||
props.selectedLearningPath !== undefined && (
|
||||
props.selectedLearningPath.hruid !== parsedLearningPath.value.hruid
|
||||
|| props.selectedLearningPath.language !== parsedLearningPath.value.language
|
||||
)
|
||||
const isIdModified = computed(
|
||||
() =>
|
||||
props.selectedLearningPath !== undefined &&
|
||||
(props.selectedLearningPath.hruid !== parsedLearningPath.value.hruid ||
|
||||
props.selectedLearningPath.language !== parsedLearningPath.value.language),
|
||||
);
|
||||
|
||||
function getErrorMessage(): string | null {
|
||||
|
@ -93,24 +99,22 @@ import { parse } from 'uuid';
|
|||
} else if (deleteError.value) {
|
||||
return t(extractErrorMessage(deleteError.value));
|
||||
} else if (isIdModified.value) {
|
||||
return t('learningPathCantModifyId');
|
||||
return t("learningPathCantModifyId");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<v-card
|
||||
:title="props.selectedLearningPath ? t('editLearningPath') : t('newLearningPath')"
|
||||
>
|
||||
<v-card :title="props.selectedLearningPath ? t('editLearningPath') : t('newLearningPath')">
|
||||
<template v-slot:text>
|
||||
<json-editor-vue v-model="learningPath"></json-editor-vue>
|
||||
<v-alert
|
||||
v-if="postError || putError || deleteError || isIdModified"
|
||||
icon="mdi mdi-alert-circle"
|
||||
type="error"
|
||||
:title="t('error')"
|
||||
:text="getErrorMessage()!"
|
||||
v-if="postError || putError || deleteError || isIdModified"
|
||||
icon="mdi mdi-alert-circle"
|
||||
type="error"
|
||||
:title="t('error')"
|
||||
:text="getErrorMessage()!"
|
||||
></v-alert>
|
||||
</template>
|
||||
<template v-slot:actions>
|
||||
|
@ -120,7 +124,7 @@ import { parse } from 'uuid';
|
|||
:loading="isPostPending || isPutPending"
|
||||
:disabled="parsedLearningPath.hruid === DEFAULT_LEARNING_PATH.hruid || isIdModified"
|
||||
>
|
||||
{{ props.selectedLearningPath ? t('saveChanges') : t('create') }}
|
||||
{{ props.selectedLearningPath ? t("saveChanges") : t("create") }}
|
||||
</v-btn>
|
||||
<button-with-confirmation
|
||||
@confirm="deleteLearningPath"
|
||||
|
@ -136,11 +140,10 @@ import { parse } from 'uuid';
|
|||
prepend-icon="mdi mdi-open-in-new"
|
||||
:disabled="!props.selectedLearningPath"
|
||||
>
|
||||
{{ t('open') }}
|
||||
{{ t("open") }}
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
</style>
|
||||
<style scoped></style>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue