mirror of
https://github.com/zadam/trilium.git
synced 2025-12-13 10:54:25 +01:00
feat(widgets/toggle): disable if going too fast
This commit is contained in:
parent
483327c808
commit
36b1182565
@ -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}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user