From c3a51cc21becfbdab7337fc4d3c45c034e4bf0d6 Mon Sep 17 00:00:00 2001 From: Elvyra <88881326+EepyElvyra@users.noreply.github.com> Date: Sun, 5 Jan 2025 22:35:20 +0100 Subject: [PATCH] fix names & give arrays a default value --- src/api/Settings.ts | 4 ++++ src/plugins/messageTags/index.ts | 2 +- src/plugins/pinDms/data.ts | 2 +- src/plugins/pinDms/index.tsx | 1 - src/utils/types.ts | 13 +++++++------ 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/api/Settings.ts b/src/api/Settings.ts index 33eb6b4a4..698a5b51a 100644 --- a/src/api/Settings.ts +++ b/src/api/Settings.ts @@ -144,6 +144,10 @@ export const SettingsStore = new SettingsStoreClass(settings, { // normal setting with a default value return (target[key] = setting.default); + else if (setting.type === OptionType.ARRAY || setting.type === OptionType.USERS || setting.type === OptionType.GUILDS || setting.type === OptionType.CHANNELS) + // if there is no default value we initialize it as an empty array + return (target[key] = []); + if (setting.type === OptionType.SELECT) { const def = setting.options.find(o => o.default); if (def) diff --git a/src/plugins/messageTags/index.ts b/src/plugins/messageTags/index.ts index 50bb62665..a41126121 100644 --- a/src/plugins/messageTags/index.ts +++ b/src/plugins/messageTags/index.ts @@ -95,7 +95,7 @@ export default definePlugin({ async start() { if (!settings.store.migrated) { const data = await DataStore.get(DATA_KEY); - if (!!data) settings.store.data = data; + if (data !== undefined) settings.store.data = data; settings.store.migrated = true; } for (const tag of settings.store.data) createTagCommand(tag); diff --git a/src/plugins/pinDms/data.ts b/src/plugins/pinDms/data.ts index f15b69480..8adc2dbfc 100644 --- a/src/plugins/pinDms/data.ts +++ b/src/plugins/pinDms/data.ts @@ -39,7 +39,7 @@ export async function init() { } export async function initCategories() { - categories = settings.store.data; + categories = settings.store.data ?? []; } export function getCategory(id: string) { diff --git a/src/plugins/pinDms/index.tsx b/src/plugins/pinDms/index.tsx index d10937997..c7c274145 100644 --- a/src/plugins/pinDms/index.tsx +++ b/src/plugins/pinDms/index.tsx @@ -49,7 +49,6 @@ export const settings = definePluginSettings({ ], onChange: () => forceUpdate() }, - dmSectioncollapsed: { type: OptionType.BOOLEAN, description: "Collapse DM sections", diff --git a/src/utils/types.ts b/src/utils/types.ts index 85d34b6e5..679085818 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -197,7 +197,7 @@ export type PluginSettingDef = ( | PluginSettingSliderDef | PluginSettingComponentDef | PluginSettingBigIntDef - | PluginSettingListDef + | PluginSettingArrayDef ) & PluginSettingCommon; export interface PluginSettingCommon { @@ -274,7 +274,7 @@ export interface PluginSettingSliderDef { stickToMarkers?: boolean; } -export interface PluginSettingListDef { +export interface PluginSettingArrayDef { type: OptionType.ARRAY | OptionType.CHANNELS | OptionType.GUILDS | OptionType.USERS; popoutText?: string; hidePopout?: boolean; @@ -314,9 +314,9 @@ type PluginSettingType = O extends PluginSettingStri O extends PluginSettingSelectDef ? O["options"][number]["value"] : O extends PluginSettingSliderDef ? number : O extends PluginSettingComponentDef ? any : - O extends PluginSettingListDef ? any[] : + O extends PluginSettingArrayDef ? any[] : never; -type PluginSettingDefaultType = O extends PluginSettingListDef ? any[] : O extends PluginSettingSelectDef ? ( +type PluginSettingDefaultType = O extends PluginSettingArrayDef ? any[] : O extends PluginSettingSelectDef ? ( O["options"] extends { default?: boolean; }[] ? O["options"][number]["value"] : undefined ) : O extends { default: infer T; } ? T : undefined; @@ -367,14 +367,15 @@ export type PluginOptionsItem = | PluginOptionBoolean | PluginOptionSelect | PluginOptionSlider - | PluginOptionComponent; + | PluginOptionComponent + | PluginOptionArray; export type PluginOptionString = PluginSettingStringDef & PluginSettingCommon & IsDisabled & IsValid; export type PluginOptionNumber = (PluginSettingNumberDef | PluginSettingBigIntDef) & PluginSettingCommon & IsDisabled & IsValid; export type PluginOptionBoolean = PluginSettingBooleanDef & PluginSettingCommon & IsDisabled & IsValid; export type PluginOptionSelect = PluginSettingSelectDef & PluginSettingCommon & IsDisabled & IsValid; export type PluginOptionSlider = PluginSettingSliderDef & PluginSettingCommon & IsDisabled & IsValid; export type PluginOptionComponent = PluginSettingComponentDef & PluginSettingCommon; -export type PluginOptionList = PluginSettingListDef & PluginSettingCommon; +export type PluginOptionArray = PluginSettingArrayDef & PluginSettingCommon; export type PluginNative any>> = { [key in keyof PluginExports]: