mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-11-08 05:03:39 +08:00
impr(validation): don't debounce if delay is zero (@fehmer, @miodec) (#6878)
after #6866 set debounceDelay to 0 for email validation
This commit is contained in:
parent
33e3acc70f
commit
a3764460e4
4 changed files with 20 additions and 4 deletions
|
|
@ -582,6 +582,9 @@ export const commandlineConfigMetadata: CommandlineConfigMetadataObject = {
|
|||
fontSize: {
|
||||
input: {
|
||||
inputValueConvert: Number,
|
||||
validation: {
|
||||
isValid: async (number: number) => number < 100,
|
||||
},
|
||||
},
|
||||
},
|
||||
fontFamily: {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,18 @@ export type Validation<T> = {
|
|||
/** Resets the value to the current config if empty */
|
||||
resetIfEmpty?: false;
|
||||
};
|
||||
|
||||
// oxlint-disable-next-line no-explicit-any
|
||||
export function debounceIfNeeded<T extends (...args: any[]) => any>(
|
||||
delay: number,
|
||||
callback: T
|
||||
): T | debounce<T> {
|
||||
if (delay === undefined || delay <= 0) {
|
||||
return callback;
|
||||
}
|
||||
return debounce(delay, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create input handler for validated input element.
|
||||
* the `callback` is called for each validation state change, including "checking".
|
||||
|
|
@ -51,7 +63,7 @@ export function createInputEventHandler<T>(
|
|||
): (e: Event) => Promise<void> {
|
||||
let callIsValid =
|
||||
validation.isValid !== undefined
|
||||
? debounce(
|
||||
? debounceIfNeeded(
|
||||
validation.debounceDelay ?? 100,
|
||||
async (
|
||||
originalInput: HTMLInputElement,
|
||||
|
|
@ -115,7 +127,7 @@ export function createInputEventHandler<T>(
|
|||
return;
|
||||
}
|
||||
|
||||
callIsValid(originalInput, currentValue, checkValue as T);
|
||||
await callIsValid(originalInput, currentValue, checkValue as T);
|
||||
//call original handler if defined
|
||||
originalInput.oninput?.(e);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ const actionModals: Record<Action, SimpleModal> = {
|
|||
{
|
||||
placeholder: "tag name",
|
||||
type: "text",
|
||||
validation: { isValid: tagNameValidation },
|
||||
validation: { isValid: tagNameValidation, debounceDelay: 0 },
|
||||
},
|
||||
],
|
||||
onlineOnly: true,
|
||||
|
|
@ -63,7 +63,7 @@ const actionModals: Record<Action, SimpleModal> = {
|
|||
{
|
||||
placeholder: "tag name",
|
||||
type: "text",
|
||||
validation: { isValid: tagNameValidation },
|
||||
validation: { isValid: tagNameValidation, debounceDelay: 0 },
|
||||
},
|
||||
],
|
||||
onlineOnly: true,
|
||||
|
|
|
|||
|
|
@ -247,6 +247,7 @@ list.updateEmail = new SimpleModal({
|
|||
isValid: async (currentValue, thisPopup) =>
|
||||
currentValue === thisPopup.inputs?.[1]?.currentValue() ||
|
||||
"Emails don't match",
|
||||
debounceDelay: 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue