mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-26 19:15:25 +03:00
refactor: move throttling to filter function
This commit is contained in:
parent
d82685a74e
commit
02e2a56cf5
@ -42,7 +42,7 @@
|
|||||||
let filterText: string | undefined = undefined;
|
let filterText: string | undefined = undefined;
|
||||||
let filteredItems: Selectable[] = items;
|
let filteredItems: Selectable[] = items;
|
||||||
|
|
||||||
function filterItems(items: Selectable[], filterText: string | undefined) {
|
const filterItems = throttle((items: Selectable[], filterText: string | undefined) => {
|
||||||
if (!filterText) {
|
if (!filterText) {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@
|
|||||||
if (!isStr(property)) return false;
|
if (!isStr(property)) return false;
|
||||||
return property.includes(filterText);
|
return property.includes(filterText);
|
||||||
});
|
});
|
||||||
}
|
}, INPUT_THROTTLE_TIME);
|
||||||
|
|
||||||
$: filteredItems = filterItems(items, filterText);
|
$: filteredItems = filterItems(items, filterText);
|
||||||
|
|
||||||
@ -111,13 +111,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleChar = throttle((char: string) => {
|
function handleChar(char: string) {
|
||||||
highlightIndex = undefined;
|
highlightIndex = undefined;
|
||||||
filterText ??= '';
|
filterText ??= '';
|
||||||
filterText += char;
|
filterText += char;
|
||||||
}, INPUT_THROTTLE_TIME);
|
}
|
||||||
|
|
||||||
const handleDelete = throttle(() => {
|
function handleDelete() {
|
||||||
if (filterText === undefined) return;
|
if (filterText === undefined) return;
|
||||||
|
|
||||||
if (filterText.length === 1) {
|
if (filterText.length === 1) {
|
||||||
@ -126,7 +126,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
filterText = filterText.slice(0, -1);
|
filterText = filterText.slice(0, -1);
|
||||||
}, INPUT_THROTTLE_TIME);
|
}
|
||||||
|
|
||||||
function handleKeyDown(e: CustomEvent<KeyboardEvent>) {
|
function handleKeyDown(e: CustomEvent<KeyboardEvent>) {
|
||||||
if (!listOpen) {
|
if (!listOpen) {
|
||||||
|
Loading…
Reference in New Issue
Block a user