diff --git a/frontend/src/lib/components/QueueSlider.svelte b/frontend/src/lib/components/QueueSlider.svelte index dec52c5..430a9bc 100644 --- a/frontend/src/lib/components/QueueSlider.svelte +++ b/frontend/src/lib/components/QueueSlider.svelte @@ -21,7 +21,7 @@ {#if i === 1}
{/if} - Song cover + Song cover {#if i === 1}

{song.title} - {song.artist}

diff --git a/frontend/src/lib/components/SuggestionInput.svelte b/frontend/src/lib/components/SuggestionInput.svelte index c93c8b7..de8e437 100644 --- a/frontend/src/lib/components/SuggestionInput.svelte +++ b/frontend/src/lib/components/SuggestionInput.svelte @@ -1,7 +1,15 @@
- - + +
diff --git a/frontend/src/lib/components/SuggestionList.svelte b/frontend/src/lib/components/SuggestionList.svelte index ba7ed69..16cc08c 100644 --- a/frontend/src/lib/components/SuggestionList.svelte +++ b/frontend/src/lib/components/SuggestionList.svelte @@ -1,32 +1,31 @@
- {#each reactiveSugg as sug} + {#each suggestions as sug}
- Song cover -

{sug.name}

+ Song cover +

{sug.title} - {sug.artist}

+1 -

{sug.points}

+

{sug.upvote}

-1
diff --git a/frontend/src/lib/types.ts b/frontend/src/lib/types.ts index 85dff04..3f10d61 100644 --- a/frontend/src/lib/types.ts +++ b/frontend/src/lib/types.ts @@ -1,12 +1,12 @@ import { z } from "zod" -export const SongSchema = z.object({ +const SongSchema = z.object({ uuid: z.string(), title: z.string(), artist: z.string(), tags: z.array(z.string()), image_id: z.string(), - youtube_id: z.number().optional().default(0), + youtube_id: z.string(), }) export type Song = z.infer @@ -25,3 +25,13 @@ export const createEmptySong = function (): Song { youtube_id: 0, } } + +const SuggestionSchema = SongSchema.extend({ + upvote: z.number(), +}) +export type Suggestion = z.infer + +export const parseSuggestion = async function (sugg: any): Promise { + let resp = await SuggestionSchema.parseAsync(sugg) + return resp +} diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte index 48f1755..3e7cfc2 100644 --- a/frontend/src/routes/+page.svelte +++ b/frontend/src/routes/+page.svelte @@ -2,11 +2,7 @@
-
+

Scan your nearby rooms

- Room Test -
-
-

Create your room

diff --git a/frontend/src/routes/room/[id]/+page.svelte b/frontend/src/routes/room/[id]/+page.svelte index 31254dd..f3905e6 100644 --- a/frontend/src/routes/room/[id]/+page.svelte +++ b/frontend/src/routes/room/[id]/+page.svelte @@ -2,14 +2,17 @@ import QueueSlider from "$lib/components/QueueSlider.svelte" import SuggestionInput from "$lib/components/SuggestionInput.svelte" import Error from "$lib/components/Error.svelte" - import { parseSong, type Song } from "$lib/types.js" + import { parseSong, parseSuggestion, type Suggestion, type Song } from "$lib/types.js" import { onMount } from "svelte" + import SuggestionList from "$lib/components/SuggestionList.svelte" let { data } = $props() let songs = $state([]) let playing = $state(0) + let suggestions = $state([]) + let error = $state({ code: 0, message: "" }) onMount(async () => { @@ -23,6 +26,25 @@ // Setup websocket connection + // 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 + }) + // Get the room queue resp = await fetch("/api/queue?room=" + data.roomId) @@ -30,13 +52,12 @@ error = { code: 404, message: "Room not found" } return } - let json = await resp.json() + json = await resp.json() json["queue"].forEach(async (i: any) => { songs.push(await parseSong(i)) }) - - // Get room suggestions + console.log(songs) }) @@ -47,10 +68,10 @@
- +
- +
{/if}