team-1/frontend/src/lib/components/SuggestionInput.svelte

41 lines
1.2 KiB
Svelte
Raw Normal View History

2025-08-01 21:10:03 +02:00
<script lang="ts">
2025-08-02 09:53:24 +02:00
import { LoaderCircle } from "@lucide/svelte"
2025-08-02 02:12:41 +02:00
2025-08-02 09:53:24 +02:00
let { roomId } = $props()
2025-08-02 02:12:41 +02:00
let input = $state("")
2025-08-02 09:53:24 +02:00
let disabled: boolean = $state(false)
2025-08-02 02:12:41 +02:00
async function sendSong() {
2025-08-02 10:28:11 +02:00
disabled = true
2025-08-02 09:19:39 +02:00
await fetch(`/api/addsong?room=${roomId}&query=${input}`, { method: "POST" })
2025-08-02 02:12:41 +02:00
input = ""
2025-08-02 10:28:11 +02:00
disabled = false
2025-08-02 02:12:41 +02:00
}
2025-08-01 21:10:03 +02:00
</script>
2025-08-02 10:28:11 +02:00
<div class={`flex h-full w-full flex-row items-center gap-2 rounded border-2 border-lime-600 bg-lime-500 ${disabled ? "disabled" : ""}`}>
2025-08-02 09:19:39 +02:00
<input
type="text"
placeholder="Song & Artist"
class="h-[50px] w-3/4 rounded px-4 font-bold text-white outline-none"
bind:value={input}
onkeydown={(e) => {
if (e.key == "Enter") {
sendSong()
}
}}
2025-08-02 09:53:24 +02:00
{disabled}
2025-08-02 09:19:39 +02:00
/>
2025-08-02 09:53:24 +02:00
{#if disabled}
<span class="animate-spin">
<LoaderCircle />
</span>
{/if}
2025-08-02 04:34:45 +02:00
<button
2025-08-02 09:19:39 +02:00
class="i-lucide-check h-[40px] w-1/4 cursor-pointer rounded border-2 border-lime-700 bg-lime-600 font-semibold text-white shadow-xl duration-100 hover:scale-105 active:scale-90"
2025-08-02 04:34:45 +02:00
onclick={sendSong}>Add</button
>
<span class="i-lucide-chevrons-left"></span>
2025-08-01 21:10:03 +02:00
</div>