From 1391b741b23b683009bff82b96da212673b4ea64 Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Fri, 11 Feb 2022 00:17:15 +0100 Subject: [PATCH] feat(ui) - auto complete debounce issue fix --- .../LiveSessionList/LiveSessionList.tsx | 2 +- .../FilterAutoComplete/FilterAutoComplete.tsx | 43 ++++++++++--------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/frontend/app/components/BugFinder/LiveSessionList/LiveSessionList.tsx b/frontend/app/components/BugFinder/LiveSessionList/LiveSessionList.tsx index 2c13d8d86..5f4bf2b46 100644 --- a/frontend/app/components/BugFinder/LiveSessionList/LiveSessionList.tsx +++ b/frontend/app/components/BugFinder/LiveSessionList/LiveSessionList.tsx @@ -84,7 +84,7 @@ function LiveSessionList(props: Props) { title={"No live sessions."} subtext={ - See how to {'enable Assist'} and ensure you're using tracker-assist v3.5.0 or higher. + See how to {'enable Assist'} and ensure you're using tracker-assist v3.5.0 or higher. } image={ null; + interface Props { showOrButton?: boolean; showCloseButton?: boolean; @@ -45,22 +47,24 @@ function FilterAutoComplete(props: Props) { const [query, setQuery] = useState(value); - const requestValues = (q) => { - setLoading(true); - - return new APIClient()[method?.toLowerCase()](endpoint, { ...params, q }) - .then(response => response.json()) - .then(({ errors, data }) => { - if (errors) { - // this.setError(); - } else { - setOptions(data); - } - }).finally(() => setLoading(false)); - // .catch(this.setError); - } - - const debouncedRequestValues = debounce(requestValues, 1000) + useEffect(() => { + const requestValues = (q) => { + setLoading(true); + + return new APIClient()[method?.toLowerCase()](endpoint, { ...params, q }) + .then(response => response.json()) + .then(({ errors, data }) => { + if (errors) { + // this.setError(); + } else { + setOptions(data); + } + }).finally(() => setLoading(false)); + + } + + debouncedRequestValues = debounce(requestValues, 1000) + }, []) const onInputChange = ({ target: { value } }) => { setQuery(value); @@ -136,11 +140,8 @@ function FilterAutoComplete(props: Props) { { !showOrButton &&
or
} - {/* */} - - { showModal && + { (showModal && (options.length > 0) || loading) && (
- { headerText && headerText } { options.map((item, i) => ( @@ -156,7 +157,7 @@ function FilterAutoComplete(props: Props) { }
- } + )} ); }