mirror of
https://github.com/anidl/multi-downloader-nx.git
synced 2026-04-20 16:02:14 +00:00
Implement search restrictions
This should prevent from sending too many API requests when searching via the GUI
This commit is contained in:
parent
190c59d1a9
commit
0da2fc232d
1 changed files with 12 additions and 8 deletions
|
|
@ -30,14 +30,18 @@ const SearchBox: React.FC = () => {
|
|||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
(async () => {
|
||||
if (search.trim().length === 0)
|
||||
return setSearchResult({ isOk: true, value: [] });
|
||||
const s = await messageHandler?.search({search});
|
||||
if (s && s.isOk)
|
||||
s.value = s.value.slice(0, 10);
|
||||
setSearchResult(s);
|
||||
})();
|
||||
if (search.trim().length === 0)
|
||||
return setSearchResult({ isOk: true, value: [] });
|
||||
|
||||
const timeOutId = setTimeout(async () => {
|
||||
if (search.trim().length > 3) {
|
||||
const s = await messageHandler?.search({search});
|
||||
if (s && s.isOk)
|
||||
s.value = s.value.slice(0, 10);
|
||||
setSearchResult(s);
|
||||
}
|
||||
}, 1000);
|
||||
return () => clearTimeout(timeOutId);
|
||||
}, [search]);
|
||||
|
||||
const anchorBounding = anchor.current?.getBoundingClientRect();
|
||||
|
|
|
|||
Loading…
Reference in a new issue