mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-24 07:25:10 +00:00
add isValid to arrays and fix types
This commit is contained in:
parent
b64523cbb6
commit
7b50083d20
2 changed files with 20 additions and 5 deletions
|
@ -72,6 +72,18 @@ export function SettingArrayComponent({
|
|||
const [text, setText] = useState<string>("");
|
||||
|
||||
useEffect(() => {
|
||||
if (text === "") {
|
||||
setError(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (option.type === OptionType.ARRAY) {
|
||||
const isValid = option.isValid?.call(definedSettings, text) ?? true;
|
||||
if (typeof isValid === "string") setError(isValid);
|
||||
else if (!isValid) setError("Invalid input provided.");
|
||||
else setError(null);
|
||||
return;
|
||||
}
|
||||
if (!isNaN(Number(text)) && text !== "") {
|
||||
if (text.length >= 18 && text.length <= 19) {
|
||||
setError(null);
|
||||
|
@ -79,7 +91,10 @@ export function SettingArrayComponent({
|
|||
setError("Invalid ID");
|
||||
}
|
||||
} else if (text !== "") {
|
||||
setError(null);
|
||||
const isValid = option.isValid?.call(definedSettings, text) ?? true;
|
||||
if (typeof isValid === "string") setError(isValid);
|
||||
else if (!isValid) setError("Invalid input provided.");
|
||||
else setError(null);
|
||||
}
|
||||
}, [text]);
|
||||
|
||||
|
@ -377,7 +392,7 @@ export function SettingArrayComponent({
|
|||
id={cl("add-button")}
|
||||
onClick={handleSubmit}
|
||||
style={{ background: "none" }}
|
||||
disabled={((text.length < 18 || text.length > 19) && option.type !== OptionType.ARRAY) || text === ""}
|
||||
disabled={((text.length < 18 || text.length > 19) && option.type !== OptionType.ARRAY) || text === "" || error != null}
|
||||
>
|
||||
<CheckMarkIcon />
|
||||
</Button> :
|
||||
|
|
|
@ -326,14 +326,14 @@ export interface PluginSettingArrayDef {
|
|||
* Only applies to User, Channel, and Guild arrays.
|
||||
*/
|
||||
hidePopout?: boolean;
|
||||
default?: any[];
|
||||
default?: string[];
|
||||
/**
|
||||
* If the setting used to be a string with a custom delimiter, you can specify the delimiter or a function to split the string
|
||||
* @default ","
|
||||
*/
|
||||
oldStringSeparator?: string | ((value: string) => string[]) | RegExp;
|
||||
|
||||
onChange?(newValue: any[]): void;
|
||||
onChange?(newValue: string[]): void;
|
||||
}
|
||||
|
||||
export interface IPluginOptionComponentProps {
|
||||
|
@ -434,7 +434,7 @@ export type PluginOptionSelect = PluginSettingSelectDef & PluginSettingCommon &
|
|||
export type PluginOptionSlider = PluginSettingSliderDef & PluginSettingCommon & IsDisabled & IsValid<number>;
|
||||
export type PluginOptionComponent = PluginSettingComponentDef & Omit<PluginSettingCommon, "description" | "placeholder">;
|
||||
export type PluginOptionCustom = PluginSettingCustomDef & Pick<PluginSettingCommon, "onChange">;
|
||||
export type PluginOptionArray = PluginSettingArrayDef & PluginSettingCommon;
|
||||
export type PluginOptionArray = PluginSettingArrayDef & PluginSettingCommon & IsDisabled & IsValid<string>;
|
||||
|
||||
export type PluginNative<PluginExports extends Record<string, (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any>> = {
|
||||
[key in keyof PluginExports]:
|
||||
|
|
Loading…
Add table
Reference in a new issue