mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 14:56:01 +00:00
added typeguard for exclusion keys
This commit is contained in:
@@ -12,10 +12,10 @@ const { mdAndUp, smAndDown } = useDisplay();
|
||||
const show = ref(false);
|
||||
const emitter = inject<Emitter<Events>>("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() {
|
||||
|
||||
@@ -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}'`);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
|
||||
@@ -2,6 +2,14 @@ import { defineStore } from "pinia";
|
||||
|
||||
import type { ConfigResponse } from "@/__generated__";
|
||||
|
||||
type ExclusionTypes =
|
||||
| "EXCLUDED_PLATFORMS"
|
||||
| "EXCLUDED_SINGLE_EXT"
|
||||
| "EXCLUDED_SINGLE_FILES"
|
||||
| "EXCLUDED_MULTI_FILES"
|
||||
| "EXCLUDED_MULTI_PARTS_EXT"
|
||||
| "EXCLUDED_MULTI_PARTS_FILES";
|
||||
|
||||
export default defineStore("config", {
|
||||
state: () => {
|
||||
return {
|
||||
@@ -37,31 +45,21 @@ export default defineStore("config", {
|
||||
removePlatformVersion(fsSlug: string) {
|
||||
delete this.config.PLATFORMS_VERSIONS[fsSlug];
|
||||
},
|
||||
addExclusion(exclusionValue: string, exclusionType: keyof ConfigResponse) {
|
||||
if (Array.isArray(this.config[exclusionType])) {
|
||||
(this.config[exclusionType] as string[]).push(exclusionValue);
|
||||
addExclusion(exclusionType: ExclusionTypes, exclusionValue: string) {
|
||||
this.config[exclusionType].push(exclusionValue);
|
||||
},
|
||||
removeExclusion(exclusionValue: string, exclusionType: ExclusionTypes) {
|
||||
const index = this.config[exclusionType].indexOf(exclusionValue);
|
||||
if (index !== -1) {
|
||||
this.config[exclusionType].splice(index, 1);
|
||||
} else {
|
||||
console.error(`Exclusion type '${exclusionType}' is not valid`);
|
||||
console.error(
|
||||
`Value '${exclusionValue}' not found in exclusion type '${exclusionType}'`,
|
||||
);
|
||||
}
|
||||
},
|
||||
removeExclusion(
|
||||
exclusionValue: string,
|
||||
exclusionType: keyof ConfigResponse,
|
||||
) {
|
||||
if (Array.isArray(this.config[exclusionType])) {
|
||||
const index = (this.config[exclusionType] as string[]).indexOf(
|
||||
exclusionValue,
|
||||
);
|
||||
if (index !== -1) {
|
||||
(this.config[exclusionType] as string[]).splice(index, 1);
|
||||
} else {
|
||||
console.error(
|
||||
`Value '${exclusionValue}' not found in '${exclusionType}'.`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.error(`Exclusion type '${exclusionType}' is not valid`);
|
||||
}
|
||||
isExclusionType(type: string): type is ExclusionTypes {
|
||||
return Object.keys(this.config).includes(type);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
6
frontend/src/types/emitter.d.ts
vendored
6
frontend/src/types/emitter.d.ts
vendored
@@ -51,7 +51,11 @@ export type Events = {
|
||||
fsSlug: string;
|
||||
slug: string;
|
||||
};
|
||||
showCreateExclusionDialog: { type: string; icon: string; title: string };
|
||||
showCreateExclusionDialog: {
|
||||
type: string;
|
||||
icon: string;
|
||||
title: string;
|
||||
};
|
||||
showCreateUserDialog: null;
|
||||
showEditUserDialog: User;
|
||||
showDeleteUserDialog: User;
|
||||
|
||||
Reference in New Issue
Block a user