diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-06-03 09:58:12 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-06-03 09:58:12 -0700 |
| commit | 88e2e3d62677f6af58b19d8e5d4d789b96d525db (patch) | |
| tree | 2934d599fa4ef8c830cddf452fbdf7e787b1ca12 /src/components/Search | |
| parent | b1c92e09707a423b7b5b01ccb60ba59a91d9f055 (diff) | |
move songs.ts to be entirely server side
Diffstat (limited to 'src/components/Search')
| -rw-r--r-- | src/components/Search/index.tsx | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index c999f97..7f9d502 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -15,11 +15,23 @@ export function Search({ currentTry, setSelectedSong }: Props) { const [results, setResults] = React.useState<Song[]>([]); React.useEffect(() => { - if (value) { - setResults(searchSong(value)); - } else if (value === "") { - setResults([]); + let cancelled = false; + + async function runSearch() { + if (!value) { + setResults([]); + return; + } + const songs = await searchSong(value); + + if (!cancelled) { + setResults(songs); + } } + runSearch(); + return () => { + cancelled = true; + }; }, [value]); // clear value on selection |
