From 39981ff794ead86f43dd080394090dfade890727 Mon Sep 17 00:00:00 2001 From: Tim Haasdyk Date: Wed, 18 Oct 2023 12:10:57 +0200 Subject: [PATCH] Add debounce to user search field --- frontend/src/lib/forms/Input.svelte | 22 ++++++++++++++----- frontend/src/lib/util/time.ts | 9 ++++++++ .../routes/(authenticated)/admin/+page.svelte | 2 +- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/frontend/src/lib/forms/Input.svelte b/frontend/src/lib/forms/Input.svelte index 7e0ad4ff8..859fa6269 100644 --- a/frontend/src/lib/forms/Input.svelte +++ b/frontend/src/lib/forms/Input.svelte @@ -1,6 +1,7 @@ - (ms = Duration.Default): Promise { return new Promise(resolve => setTimeout(resolve, ms)); } + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function debounce

(fn: (...args: P) => void, debounceTime: number): (...args: P) => void { + let timeout: ReturnType; + return (...args: P) => { + clearTimeout(timeout); + timeout = setTimeout(() => fn(...args), debounceTime); + }; +} diff --git a/frontend/src/routes/(authenticated)/admin/+page.svelte b/frontend/src/routes/(authenticated)/admin/+page.svelte index 6640a6c72..933c7ee40 100644 --- a/frontend/src/routes/(authenticated)/admin/+page.svelte +++ b/frontend/src/routes/(authenticated)/admin/+page.svelte @@ -90,7 +90,7 @@ - +