2025-08-01 22:17:26 +02:00
|
|
|
<script lang="ts">
|
|
|
|
import QueueSlider from "$lib/components/QueueSlider.svelte"
|
|
|
|
import SuggestionInput from "$lib/components/SuggestionInput.svelte"
|
2025-08-02 00:52:13 +02:00
|
|
|
import Error from "$lib/components/Error.svelte"
|
2025-08-02 02:12:41 +02:00
|
|
|
import { parseSong, parseSuggestion, type Suggestion, type Song } from "$lib/types.js"
|
2025-08-02 00:52:13 +02:00
|
|
|
import { onMount } from "svelte"
|
2025-08-02 02:12:41 +02:00
|
|
|
import SuggestionList from "$lib/components/SuggestionList.svelte"
|
2025-08-02 00:52:13 +02:00
|
|
|
|
|
|
|
let { data } = $props()
|
|
|
|
|
|
|
|
let songs = $state<Song[]>([])
|
|
|
|
let playing = $state(0)
|
|
|
|
|
2025-08-02 02:12:41 +02:00
|
|
|
let suggestions = $state<Suggestion[]>([])
|
|
|
|
|
2025-08-02 00:52:13 +02:00
|
|
|
let error = $state({ code: 0, message: "" })
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
// Join the room
|
|
|
|
let resp = await fetch("/api/join?room=" + data.roomId)
|
|
|
|
|
|
|
|
if (resp.status != 200) {
|
|
|
|
error = { code: 400, message: "Failed to join the room. Maybe wrong code or location?" }
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup websocket connection
|
|
|
|
|
2025-08-02 02:12:41 +02:00
|
|
|
// Get room suggestions
|
|
|
|
|
|
|
|
resp = await fetch("/api/room/suggestions?room=" + data.roomId)
|
|
|
|
|
|
|
|
if (resp.status != 200) {
|
|
|
|
error = { code: 500, message: "Failed to retrive suggestions" }
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let json = await resp.json()
|
|
|
|
|
|
|
|
json["songs"].forEach(async (i: any) => {
|
|
|
|
suggestions.push(await parseSuggestion(i))
|
|
|
|
})
|
|
|
|
|
|
|
|
suggestions = suggestions.sort((a, b) => {
|
|
|
|
return a.upvote - b.upvote
|
|
|
|
})
|
|
|
|
|
2025-08-02 00:52:13 +02:00
|
|
|
// Get the room queue
|
|
|
|
|
|
|
|
resp = await fetch("/api/queue?room=" + data.roomId)
|
|
|
|
if (resp.status != 200) {
|
|
|
|
error = { code: 404, message: "Room not found" }
|
|
|
|
return
|
|
|
|
}
|
2025-08-02 02:12:41 +02:00
|
|
|
json = await resp.json()
|
2025-08-02 00:52:13 +02:00
|
|
|
|
|
|
|
json["queue"].forEach(async (i: any) => {
|
|
|
|
songs.push(await parseSong(i))
|
|
|
|
})
|
2025-08-02 02:12:41 +02:00
|
|
|
console.log(songs)
|
2025-08-02 00:52:13 +02:00
|
|
|
})
|
2025-08-01 22:17:26 +02:00
|
|
|
</script>
|
|
|
|
|
2025-08-02 00:52:13 +02:00
|
|
|
<!-- Check if the room exists -->
|
|
|
|
{#if error.code != 0}
|
|
|
|
<Error code={error.code} message={error.message} />
|
|
|
|
{:else}
|
|
|
|
<div class="flex w-full flex-col items-center justify-center p-4 lg:p-10">
|
|
|
|
<QueueSlider {songs} {playing} />
|
|
|
|
<div class="w-full py-6 lg:w-[30vw]">
|
2025-08-02 02:12:41 +02:00
|
|
|
<SuggestionInput roomId={data.roomId} />
|
2025-08-02 00:52:13 +02:00
|
|
|
</div>
|
|
|
|
<div class="w-full py-6 lg:w-[30vw]">
|
2025-08-02 02:12:41 +02:00
|
|
|
<SuggestionList {suggestions} roomId={data.roomId} />
|
2025-08-02 00:52:13 +02:00
|
|
|
</div>
|
2025-08-01 22:17:26 +02:00
|
|
|
</div>
|
2025-08-02 00:52:13 +02:00
|
|
|
{/if}
|