diff options
author | Dossy Shiobara <dossy@panoptic.com> | 2023-03-20 22:16:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-21 02:16:01 +0000 |
commit | 37c2a8a5de74af1bc5671566877763ba1fb7cb40 (patch) | |
tree | 8867da6e76b1138461f1881bdd43743032d0339c /src | |
parent | 265547213cc67cc0c1615302367593ce888fb899 (diff) | |
download | Vencord-37c2a8a5de74af1bc5671566877763ba1fb7cb40.tar.gz Vencord-37c2a8a5de74af1bc5671566877763ba1fb7cb40.tar.bz2 Vencord-37c2a8a5de74af1bc5671566877763ba1fb7cb40.zip |
fix: settings input validation and error handling (#609)
Co-authored-by: Ven <vendicated@riseup.net>
Diffstat (limited to 'src')
3 files changed, 6 insertions, 1 deletions
diff --git a/src/components/PluginSettings/components/SettingNumericComponent.tsx b/src/components/PluginSettings/components/SettingNumericComponent.tsx index 12e8e36..446d250 100644 --- a/src/components/PluginSettings/components/SettingNumericComponent.tsx +++ b/src/components/PluginSettings/components/SettingNumericComponent.tsx @@ -38,9 +38,12 @@ export function SettingNumericComponent({ option, pluginSettings, definedSetting function handleChange(newValue) { const isValid = option.isValid?.call(definedSettings, newValue) ?? true; + + setError(null); if (typeof isValid === "string") setError(isValid); else if (!isValid) setError("Invalid input provided."); - else if (option.type === OptionType.NUMBER && BigInt(newValue) >= MAX_SAFE_NUMBER) { + + if (option.type === OptionType.NUMBER && BigInt(newValue) >= MAX_SAFE_NUMBER) { setState(`${Number.MAX_SAFE_INTEGER}`); onChange(serialize(newValue)); } else { diff --git a/src/components/PluginSettings/components/SettingSelectComponent.tsx b/src/components/PluginSettings/components/SettingSelectComponent.tsx index 164a29a..97c1707 100644 --- a/src/components/PluginSettings/components/SettingSelectComponent.tsx +++ b/src/components/PluginSettings/components/SettingSelectComponent.tsx @@ -36,6 +36,7 @@ export function SettingSelectComponent({ option, pluginSettings, definedSettings if (typeof isValid === "string") setError(isValid); else if (!isValid) setError("Invalid input provided."); else { + setError(null); setState(newValue); onChange(newValue); } diff --git a/src/components/PluginSettings/components/SettingTextComponent.tsx b/src/components/PluginSettings/components/SettingTextComponent.tsx index 599593f..9eccb10 100644 --- a/src/components/PluginSettings/components/SettingTextComponent.tsx +++ b/src/components/PluginSettings/components/SettingTextComponent.tsx @@ -34,6 +34,7 @@ export function SettingTextComponent({ option, pluginSettings, definedSettings, if (typeof isValid === "string") setError(isValid); else if (!isValid) setError("Invalid input provided."); else { + setError(null); setState(newValue); onChange(newValue); } |