From a4fd446c9ae0cdeaea4267d5c6b6ca5f35df4ba5 Mon Sep 17 00:00:00 2001 From: zurdi Date: Thu, 24 Oct 2024 23:47:20 +0000 Subject: [PATCH] added typeguard for exclusion keys --- .../Management/Dialog/CreateExclusion.vue | 24 ++++++----- .../components/Management/ExcludedCard.vue | 16 ++++--- frontend/src/stores/config.ts | 42 +++++++++---------- frontend/src/types/emitter.d.ts | 6 ++- 4 files changed, 49 insertions(+), 39 deletions(-) diff --git a/frontend/src/components/Management/Dialog/CreateExclusion.vue b/frontend/src/components/Management/Dialog/CreateExclusion.vue index 22ee6719d..68d63807a 100644 --- a/frontend/src/components/Management/Dialog/CreateExclusion.vue +++ b/frontend/src/components/Management/Dialog/CreateExclusion.vue @@ -12,10 +12,10 @@ const { mdAndUp, smAndDown } = useDisplay(); const show = ref(false); const emitter = inject>("emitter"); const configStore = storeConfig(); -const exclusionValue = ref(""); -const exclusionType = ref(""); -const exclusionIcon = ref(""); -const exclusionTitle = ref(""); +const exclusionValue = ref(); +const exclusionType = ref(); +const exclusionIcon = ref(); +const exclusionTitle = ref(); emitter?.on("showCreateExclusionDialog", ({ type, icon, title }) => { exclusionType.value = type; exclusionIcon.value = icon; @@ -25,12 +25,16 @@ emitter?.on("showCreateExclusionDialog", ({ type, icon, title }) => { // Functions function addExclusion() { - configApi.addExclusion({ - exclusionValue: exclusionValue.value, - exclusionType: exclusionType.value, - }); - configStore.addExclusion(exclusionValue.value, exclusionType.value); - closeDialog(); + if (configStore.isExclusionType(exclusionType.value)) { + configApi.addExclusion({ + exclusionValue: exclusionValue.value, + exclusionType: exclusionType.value, + }); + configStore.addExclusion(exclusionType.value, exclusionValue.value); + closeDialog(); + } else { + console.error(`Invalid exclusion type '${exclusionType.value}'`); + } } function closeDialog() { diff --git a/frontend/src/components/Management/ExcludedCard.vue b/frontend/src/components/Management/ExcludedCard.vue index 90577d945..7daea0a3d 100644 --- a/frontend/src/components/Management/ExcludedCard.vue +++ b/frontend/src/components/Management/ExcludedCard.vue @@ -12,17 +12,21 @@ const props = defineProps<{ editable: boolean; title: string; type: string; - icon?: string; + icon: string; }>(); const configStore = storeConfig(); // Functions function removeExclusion(exclusionValue: string) { - configApi.deleteExclusion({ - exclusionValue: exclusionValue, - exclusionType: props.type, - }); - configStore.removeExclusion(exclusionValue, props.type); + if (configStore.isExclusionType(props.type)) { + configApi.deleteExclusion({ + exclusionValue: exclusionValue, + exclusionType: props.type, + }); + configStore.removeExclusion(exclusionValue, props.type); + } else { + console.error(`Invalid exclusion type '${props.type}'`); + } }