Skip to content

Build your personal knowledge base with Trilium Notes

feat(react/promoted_attributes): debounce label editing

Elian Doran3fde546b837c
diff --git a/apps/client/src/services/debounce.ts b/apps/client/src/services/debounce.ts
index 3ccfcd6e5a..4f16cc190d 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<T>(func: (...args: unknown[]) => T, waitMs: number, immediate: boolean = false) {
+function debounce<T>(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 1d3823da5d..ad501e35d6 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) {