Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(widgets/toggle): disable if going too fast
Elian Doran36b1182565b0
diff --git a/apps/client/src/widgets/react/FormList.tsx b/apps/client/src/widgets/react/FormList.tsxindex f1374712c1..fac69efdef 100644--- a/apps/client/src/widgets/react/FormList.tsx+++ b/apps/client/src/widgets/react/FormList.tsx@@ -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;currentValue: boolean;- onChange(newValue: boolean): void;+ onChange(newValue: boolean): void | Promise<void>;}) {+ const isWaiting = useRef(false);+return (- <FormListItem {...props} onClick={(e) => {- e.stopPropagation();- if (!props.disabled) {- onChange(!currentValue);- }- }}>+ <FormListItem+ {...props}+ disabled={disabled}+ onClick={async (e) => {+ e.stopPropagation();+ if (!disabled && !isWaiting.current) {+ isWaiting.current = true;+ await onChange(!currentValue);+ isWaiting.current = false;+ }+ }}><FormToggleswitchOnName={title}switchOffName={title}