feat(react/promoted_attributes): debounce label editing

This commit is contained in:
Elian Doran 2025-11-23 13:43:40 +02:00
parent a12b3cb51a
commit 3fde546b83
No known key found for this signature in database
2 changed files with 5 additions and 2 deletions

View File

@ -12,7 +12,7 @@
* @param whether to execute at the beginning (`false`) * @param whether to execute at the beginning (`false`)
* @api public * @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 timeout: any; // TODO: fix once we split client and server.
let args: unknown[] | null; let args: unknown[] | null;
let context: unknown; let context: unknown;

View File

@ -13,6 +13,7 @@ import NoteAutocomplete from "./react/NoteAutocomplete";
import ws from "../services/ws"; import ws from "../services/ws";
import { UpdateAttributeResponse } from "@triliumnext/commons"; import { UpdateAttributeResponse } from "@triliumnext/commons";
import attributes from "../services/attributes"; import attributes from "../services/attributes";
import debounce from "../services/debounce";
interface Cell { interface Cell {
definitionAttr: FAttribute; definitionAttr: FAttribute;
@ -419,7 +420,7 @@ function setupTextLabelAutocomplete(el: HTMLInputElement, valueAttr: Attribute,
} }
function buildPromotedAttributeLabelChangedListener({ note, cell, componentId, ...props }: CellProps): OnChangeListener { function buildPromotedAttributeLabelChangedListener({ note, cell, componentId, ...props }: CellProps): OnChangeListener {
return async (e: OnChangeEventData) => { async function onChange(e: OnChangeEventData) {
const inputEl = e.target as HTMLInputElement; const inputEl = e.target as HTMLInputElement;
let value: string; let value: string;
@ -431,6 +432,8 @@ function buildPromotedAttributeLabelChangedListener({ note, cell, componentId, .
cell.valueAttr.attributeId = (await updateAttribute(note, cell, componentId, value)).attributeId; cell.valueAttr.attributeId = (await updateAttribute(note, cell, componentId, value)).attributeId;
} }
return debounce(onChange, 250);
} }
function updateAttribute(note: FNote, cell: Cell, componentId: string, value: string) { function updateAttribute(note: FNote, cell: Cell, componentId: string, value: string) {