feat(widgets/toggle): disable if going too fast

This commit is contained in:
Elian Doran 2025-12-10 20:32:58 +02:00
parent 483327c808
commit 36b1182565
No known key found for this signature in database

View File

@ -133,18 +133,25 @@ export function FormListItem({ className, icon, value, title, active, disabled,
); );
} }
export function FormListToggleableItem({ title, currentValue, onChange, ...props }: Omit<FormListItemOpts, "onClick" | "children"> & { export function FormListToggleableItem({ title, currentValue, onChange, disabled, ...props }: Omit<FormListItemOpts, "onClick" | "children"> & {
title: string; title: string;
currentValue: boolean; currentValue: boolean;
onChange(newValue: boolean): void; onChange(newValue: boolean): void | Promise<void>;
}) { }) {
const isWaiting = useRef(false);
return ( return (
<FormListItem {...props} onClick={(e) => { <FormListItem
e.stopPropagation(); {...props}
if (!props.disabled) { disabled={disabled}
onChange(!currentValue); onClick={async (e) => {
} e.stopPropagation();
}}> if (!disabled && !isWaiting.current) {
isWaiting.current = true;
await onChange(!currentValue);
isWaiting.current = false;
}
}}>
<FormToggle <FormToggle
switchOnName={title} switchOnName={title}
switchOffName={title} switchOffName={title}