From 3fde546b837c3d691c0196d7600e6f39f492ea07 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 23 Nov 2025 13:43:40 +0200 Subject: [PATCH] feat(react/promoted_attributes): debounce label editing --- apps/client/src/services/debounce.ts | 2 +- apps/client/src/widgets/PromotedAttributes.tsx | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/client/src/services/debounce.ts b/apps/client/src/services/debounce.ts index 3ccfcd6e5..4f16cc190 100644 --- a/apps/client/src/services/debounce.ts +++ b/apps/client/src/services/debounce.ts @@ -12,7 +12,7 @@ * @param whether to execute at the beginning (`false`) * @api public */ -function debounce(func: (...args: unknown[]) => T, waitMs: number, immediate: boolean = false) { +function debounce(func: (...args: any[]) => T, waitMs: number, immediate: boolean = false) { let timeout: any; // TODO: fix once we split client and server. let args: unknown[] | null; let context: unknown; diff --git a/apps/client/src/widgets/PromotedAttributes.tsx b/apps/client/src/widgets/PromotedAttributes.tsx index 1d3823da5..ad501e35d 100644 --- a/apps/client/src/widgets/PromotedAttributes.tsx +++ b/apps/client/src/widgets/PromotedAttributes.tsx @@ -13,6 +13,7 @@ import NoteAutocomplete from "./react/NoteAutocomplete"; import ws from "../services/ws"; import { UpdateAttributeResponse } from "@triliumnext/commons"; import attributes from "../services/attributes"; +import debounce from "../services/debounce"; interface Cell { definitionAttr: FAttribute; @@ -419,7 +420,7 @@ function setupTextLabelAutocomplete(el: HTMLInputElement, valueAttr: Attribute, } function buildPromotedAttributeLabelChangedListener({ note, cell, componentId, ...props }: CellProps): OnChangeListener { - return async (e: OnChangeEventData) => { + async function onChange(e: OnChangeEventData) { const inputEl = e.target as HTMLInputElement; let value: string; @@ -431,6 +432,8 @@ function buildPromotedAttributeLabelChangedListener({ note, cell, componentId, . cell.valueAttr.attributeId = (await updateAttribute(note, cell, componentId, value)).attributeId; } + + return debounce(onChange, 250); } function updateAttribute(note: FNote, cell: Cell, componentId: string, value: string) {