mirror of
https://github.com/zadam/trilium.git
synced 2025-11-26 10:34:25 +01:00
feat(react/promoted_attributes): debounce label editing
This commit is contained in:
parent
a12b3cb51a
commit
3fde546b83
@ -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;
|
||||||
|
|||||||
@ -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) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user