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>("");
|
const [text, setText] = useState<string>("");
|
||||||
|
|
||||||
useEffect(() => {
|
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 (!isNaN(Number(text)) && text !== "") {
|
||||||
if (text.length >= 18 && text.length <= 19) {
|
if (text.length >= 18 && text.length <= 19) {
|
||||||
setError(null);
|
setError(null);
|
||||||
|
@ -79,7 +91,10 @@ export function SettingArrayComponent({
|
||||||
setError("Invalid ID");
|
setError("Invalid ID");
|
||||||
}
|
}
|
||||||
} else if (text !== "") {
|
} 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]);
|
}, [text]);
|
||||||
|
|
||||||
|
@ -377,7 +392,7 @@ export function SettingArrayComponent({
|
||||||
id={cl("add-button")}
|
id={cl("add-button")}
|
||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
style={{ background: "none" }}
|
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 />
|
<CheckMarkIcon />
|
||||||
</Button> :
|
</Button> :
|
||||||
|
|
|
@ -326,14 +326,14 @@ export interface PluginSettingArrayDef {
|
||||||
* Only applies to User, Channel, and Guild arrays.
|
* Only applies to User, Channel, and Guild arrays.
|
||||||
*/
|
*/
|
||||||
hidePopout?: boolean;
|
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
|
* 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 ","
|
* @default ","
|
||||||
*/
|
*/
|
||||||
oldStringSeparator?: string | ((value: string) => string[]) | RegExp;
|
oldStringSeparator?: string | ((value: string) => string[]) | RegExp;
|
||||||
|
|
||||||
onChange?(newValue: any[]): void;
|
onChange?(newValue: string[]): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPluginOptionComponentProps {
|
export interface IPluginOptionComponentProps {
|
||||||
|
@ -434,7 +434,7 @@ export type PluginOptionSelect = PluginSettingSelectDef & PluginSettingCommon &
|
||||||
export type PluginOptionSlider = PluginSettingSliderDef & PluginSettingCommon & IsDisabled & IsValid<number>;
|
export type PluginOptionSlider = PluginSettingSliderDef & PluginSettingCommon & IsDisabled & IsValid<number>;
|
||||||
export type PluginOptionComponent = PluginSettingComponentDef & Omit<PluginSettingCommon, "description" | "placeholder">;
|
export type PluginOptionComponent = PluginSettingComponentDef & Omit<PluginSettingCommon, "description" | "placeholder">;
|
||||||
export type PluginOptionCustom = PluginSettingCustomDef & Pick<PluginSettingCommon, "onChange">;
|
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>> = {
|
export type PluginNative<PluginExports extends Record<string, (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any>> = {
|
||||||
[key in keyof PluginExports]:
|
[key in keyof PluginExports]:
|
||||||
|
|
Loading…
Add table
Reference in a new issue