diff --git a/src/api/Settings.ts b/src/api/Settings.ts index 698a5b51a..7fb1193b0 100644 --- a/src/api/Settings.ts +++ b/src/api/Settings.ts @@ -225,12 +225,14 @@ export function migratePluginSettings(name: string, ...oldNames: string[]) { } export function migrateSettingsToArrays(pluginName: string, settings: string[], stringSeparator: string = ",") { + const { plugins } = SettingsStore.plain; + for (const setting of settings) { - if (SettingsStore.plain.plugins[pluginName] === undefined || typeof SettingsStore.plain.plugins[pluginName][setting] !== "string") continue; + if (plugins[pluginName] === undefined || typeof plugins[pluginName][setting] !== "string") continue; logger.info(`Migrating setting ${setting} from ${pluginName} to list`); // @ts-ignore - if (SettingsStore.plain.plugins[pluginName][setting] === "") SettingsStore.plain.plugins[pluginName][setting] = SettingsStore.plain.plugins[pluginName][setting].default ?? []; - else SettingsStore.plain.plugins[pluginName][setting] = SettingsStore.plain.plugins[pluginName][setting].split(stringSeparator); + if (plugins[pluginName][setting] === "") plugins[pluginName][setting] = plugins[pluginName][setting].default ?? []; + else plugins[pluginName][setting] = plugins[pluginName][setting].split(stringSeparator); } } diff --git a/src/components/PluginSettings/components/SettingArrayComponent.tsx b/src/components/PluginSettings/components/SettingArrayComponent.tsx index 7cd188223..35ee43cb0 100644 --- a/src/components/PluginSettings/components/SettingArrayComponent.tsx +++ b/src/components/PluginSettings/components/SettingArrayComponent.tsx @@ -60,6 +60,21 @@ export function SettingArrayComponent({ const [items, setItems] = useState([]); const [text, setText] = useState(""); + useEffect(() => { + if (text === "") { + setError(null); + } else if (!isNaN(Number(text))) { + if (text.length >= 18 && text.length <= 19) { + setError(null); + } else { + setError("Invalid ID"); + } + } else { + setError(null); + } + }, [text]); + + useEffect(() => { pluginSettings[id] = items; onChange(items); @@ -373,21 +388,6 @@ export function SettingArrayComponent({ } function handleSubmit() { - if (text === "") { - return; - } - if (option.type !== OptionType.ARRAY) { - if (isNaN(Number(text))) { - openSearchModal(text); - setText(""); - return; - } - if (!(text.length >= 18 && text.length <= 19)) { - setError("Invalid ID"); - return; - } - } - if (items.includes(text)) { setError("This item is already added"); setText(""); @@ -437,29 +437,33 @@ export function SettingArrayComponent({ > setText(v)} value={text} /> - - + {text === "" ? null : + !isNaN(Number(text)) ? + : + < Button + id={cl("search-button")} + size={Button.Sizes.MIN} + onClick={() => openSearchModal(text)} + style={ + { background: "none" } + } + > + + + } {error && {error}}