From 322a8f3daa04688d225a5ddb8accc7a7c33cf9d9 Mon Sep 17 00:00:00 2001 From: MiniDigger | Martin Date: Thu, 25 Jul 2024 22:31:20 +0200 Subject: [PATCH] fix: random warnings --- frontend/src/components/design/Spinner.vue | 2 +- .../src/components/modals/NewPageModal.vue | 22 +++++++++---------- frontend/src/composables/useErrorHandling.ts | 12 +++++++--- .../src/composables/useValidationHelpers.ts | 6 ++--- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/design/Spinner.vue b/frontend/src/components/design/Spinner.vue index 9c16075d3..e6e3b0a36 100644 --- a/frontend/src/components/design/Spinner.vue +++ b/frontend/src/components/design/Spinner.vue @@ -46,7 +46,7 @@ const circleRadius = computed(() => (props.diameter - props.stroke) / 2); const circleCircumference = computed(() => 2 * Math.PI * circleRadius.value); watch( - props, + () => props, () => { attachSvgStyle(); attachCircleStyle(); diff --git a/frontend/src/components/modals/NewPageModal.vue b/frontend/src/components/modals/NewPageModal.vue index d588fa32c..dac89442a 100644 --- a/frontend/src/components/modals/NewPageModal.vue +++ b/frontend/src/components/modals/NewPageModal.vue @@ -16,15 +16,13 @@ const updateProjectPagesCallback = inject<(pages: HangarProjectPage[]) => void>( const modal = ref(null); // Filled by vue const pageRoots = computed(() => [{ value: -1, text: "" }, ...flatDeep(props.pages, "")]); -const name = ref(""); -const parent = ref(); const loading = ref(false); -const body = computed(() => ({ +const body = reactive({ projectId: props.projectId, - name: name.value, - parentId: parent.value === -1 ? undefined : parent.value, -})); + name: "", + parentId: undefined as number | undefined, +}); const rules = [ required(), maxLength()(useBackendData.validations.project.pageName.max!), @@ -49,12 +47,12 @@ async function createPage() { loading.value = true; if (!(await v.value.$validate())) return; const slug = await useInternalApi(`pages/create/${props.projectId}`, "post", { - name: name.value, - parentId: parent.value === -1 ? null : parent.value, + name: body.name, + parentId: body.parentId === -1 ? null : body.parentId, }); - name.value = ""; - parent.value = undefined; + body.name = ""; + body.parentId = undefined; if (updateProjectPagesCallback) { updateProjectPagesCallback(await useInternalApi(`pages/list/${props.projectId}`, "get")); @@ -74,14 +72,14 @@ async function createPage() {
- +
diff --git a/frontend/src/composables/useErrorHandling.ts b/frontend/src/composables/useErrorHandling.ts index 955e6cb9d..c708a6b41 100644 --- a/frontend/src/composables/useErrorHandling.ts +++ b/frontend/src/composables/useErrorHandling.ts @@ -2,9 +2,15 @@ import type { AxiosError } from "axios"; import { isAxiosError } from "axios"; import type { Composer } from "vue-i18n"; import type { HangarApiException, HangarValidationException, MultiHangarApiException } from "~/types/backend"; +import { tryUseNuxtApp } from "#app/nuxt"; export function handleRequestError(err: AxiosError | unknown, msg: string | undefined = undefined, alwaysShowErrorPage = false) { - const i18n = useNuxtApp().$i18n; + const i18n = tryUseNuxtApp()?.$i18n; + if (!i18n) { + console.error("didnt find i18n!"); + _handleRequestError(err, i18n); + return; + } if (import.meta.env.SSR || alwaysShowErrorPage) { _handleRequestError(err, i18n); } @@ -55,7 +61,7 @@ export function handleRequestError(err: AxiosError | unknown, msg: string | unde } } -function _handleRequestError(err: AxiosError | unknown, i18n: Composer) { +function _handleRequestError(err: AxiosError | unknown, i18n?: Composer) { const transformed = transformAxiosError(err); if (!isAxiosError(err)) { // everything should be an AxiosError @@ -69,7 +75,7 @@ function _handleRequestError(err: AxiosError | unknown, i18n: Composer) { "isMultiException" in err.response.data ? (err.response.data as MultiHangarApiException).exceptions?.[0] : (err.response.data as HangarApiException); createError({ statusCode: data?.httpError.statusCode, - statusMessage: data?.message ? (i18n.te(data.message) ? i18n.t(data.message) : data.message) : undefined, + statusMessage: data?.message ? (i18n?.te(data.message) ? i18n.t(data.message) : data.message) : undefined, }); } else if ("isHangarValidationException" in err.response.data) { const data = err.response.data as HangarValidationException; diff --git a/frontend/src/composables/useValidationHelpers.ts b/frontend/src/composables/useValidationHelpers.ts index 85fbec02f..d2f7ee341 100644 --- a/frontend/src/composables/useValidationHelpers.ts +++ b/frontend/src/composables/useValidationHelpers.ts @@ -1,5 +1,5 @@ import { type ErrorObject, useVuelidate, type ValidationRule } from "@vuelidate/core"; -import type { ComputedRef, Ref } from "vue"; +import type { Ref } from "vue"; import * as validators from "@vuelidate/validators"; import { createI18nMessage, helpers, type ValidatorWrapper } from "@vuelidate/validators"; import { difference, isEmpty, uniq } from "lodash-es"; @@ -98,12 +98,12 @@ export const noDuplicated = withOverrideMessage((elements: any[] | (() => any[]) }) ); -export const validPageName = withOverrideMessage((body: ComputedRef<{ projectId: number; parentId?: number; name: string }>) => +export const validPageName = withOverrideMessage((body: { projectId: number; parentId?: number; name: string }) => helpers.withParams( { body, type: "validPageName" }, helpers.withAsync(async () => { try { - await useInternalApi("pages/checkName", "get", body.value); + await useInternalApi("pages/checkName", "get", body); return { $valid: true }; } catch (e: AxiosError | any) { if (e?.response?.data?.detail) {