From 88e2e3d62677f6af58b19d8e5d4d789b96d525db Mon Sep 17 00:00:00 2001
From: Pinapelz <yukais@pinapelz.com>
Date: Wed, 3 Jun 2026 09:58:12 -0700
Subject: move songs.ts to be entirely server side

---
 src/components/Search/index.tsx | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

(limited to 'src/components/Search/index.tsx')

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
-- 
cgit v1.2.3

