Implement search restrictions

This should prevent from sending too many API requests when searching via the GUI
This commit is contained in:
AnimeDL 2023-07-03 18:00:07 -07:00
parent 190c59d1a9
commit 0da2fc232d

View file

@ -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();