From f444782ab2f19a523097eeac92db825ed99aeabb Mon Sep 17 00:00:00 2001 From: Tudorel Oprisan Date: Fri, 20 Dec 2024 22:42:28 +0000 Subject: [PATCH] list songs based on search --- subsonic-ui-svelte/index.html | 2 +- subsonic-ui-svelte/src/App.svelte | 2 + .../src/components/Search.svelte | 180 ++++++++++++++++++ subsonic-ui-svelte/src/lib/api.ts | 30 +-- 4 files changed, 192 insertions(+), 22 deletions(-) create mode 100644 subsonic-ui-svelte/src/components/Search.svelte diff --git a/subsonic-ui-svelte/index.html b/subsonic-ui-svelte/index.html index b6c5f0a..90ea09d 100644 --- a/subsonic-ui-svelte/index.html +++ b/subsonic-ui-svelte/index.html @@ -4,7 +4,7 @@ - Vite + Svelte + TS + Discord music bot remote
diff --git a/subsonic-ui-svelte/src/App.svelte b/subsonic-ui-svelte/src/App.svelte index dccf1ac..6bad1ac 100644 --- a/subsonic-ui-svelte/src/App.svelte +++ b/subsonic-ui-svelte/src/App.svelte @@ -1,9 +1,11 @@

Navidrome Frontend

+
diff --git a/subsonic-ui-svelte/src/components/Search.svelte b/subsonic-ui-svelte/src/components/Search.svelte new file mode 100644 index 0000000..b22110b --- /dev/null +++ b/subsonic-ui-svelte/src/components/Search.svelte @@ -0,0 +1,180 @@ + + +
+ + + {#if loading} +
Loading search results...
+ {:else if error} +
{error}
+ {:else if searchResults.length > 0} + + {:else} +
No results found
+ {/if} +
+ + diff --git a/subsonic-ui-svelte/src/lib/api.ts b/subsonic-ui-svelte/src/lib/api.ts index 0c3db26..3423f78 100644 --- a/subsonic-ui-svelte/src/lib/api.ts +++ b/subsonic-ui-svelte/src/lib/api.ts @@ -3,27 +3,6 @@ const API_VERSION = "1.16.1"; // Replace with the Subsonic API version you're us const API_PASSWORD = "xWPciqjr5VSVDvVS0sAH9L8gKEQm42"; // Replace with your actual token const API_CLIENT = "SvelteApp"; -// export async function fetchFromAPI(endpoint: string, params: Record) { -// const url = new URL(`${API_URL}/${endpoint}`); -// url.search = new URLSearchParams({ -// ...params, -// v: API_VERSION, -// c: API_CLIENT, -// f: "json", // Always request JSON format -// u: "drome", // Replace with your username -// p: API_PASSWORD -// //t: API_TOKEN, // Your token -// //s: "salt", // Optional if you're using salted tokens -// }).toString(); - - -// const response = await fetch(url.toString()); -// if (!response.ok) { -// throw new Error(`API request failed: ${response.statusText}`); -// } -// return response.json(); -// } - export async function fetchFromAPI(endpoint: string, params: Record) { const url = new URL(`${API_URL}/${endpoint}`); @@ -65,3 +44,12 @@ export async function fetchFromAPI(endpoint: string, params: Record; + +export const debounce = (callback: () => void, delay: number) => { + if (debounceTimeout) { + clearTimeout(debounceTimeout); // Clear the previous timeout + } + debounceTimeout = setTimeout(callback, delay); +};