Playlists are not gotten through actual spotify api for User

This commit is contained in:
Pablu23
2025-10-11 16:10:32 +02:00
parent f03d1d1a63
commit 62fe3456c3
4 changed files with 26 additions and 57 deletions

2
src/app.d.ts vendored
View File

@@ -30,7 +30,7 @@ export interface GameMode {
} }
export interface Playlist { export interface Playlist {
id: number; id: string;
name: string; name: string;
imageUrl: string; imageUrl: string;
songCount: number; songCount: number;

View File

@@ -22,15 +22,6 @@
selectedPlaylistId: settings.selectedPlaylistId selectedPlaylistId: settings.selectedPlaylistId
}); });
// $effect(() => {
// // Update local settings when change
// localSettings = {
// maxPlayers: settings.maxPlayers,
// gameMode: settings.gameMode,
// selectedPlaylistId: settings.selectedPlaylistId
// };
// });
function updateMaxPlayers(value: number) { function updateMaxPlayers(value: number) {
if (value >= 2 && value <= 16) { if (value >= 2 && value <= 16) {
localSettings.maxPlayers = value; localSettings.maxPlayers = value;

View File

@@ -1,7 +1,7 @@
import { redirect } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from './$types';
import type { User } from '../../../app'; import type { User } from '../../../app';
import type { Settings } from '$lib/types'; import type { Playlist, Settings } from '$lib/types';
import { env } from '$env/dynamic/public'; import { env } from '$env/dynamic/public';
export const load: PageServerLoad = async ({ params, fetch, locals: { user } }) => { export const load: PageServerLoad = async ({ params, fetch, locals: { user } }) => {
@@ -11,13 +11,12 @@ export const load: PageServerLoad = async ({ params, fetch, locals: { user } })
if (!env.PUBLIC_API_BASE) redirect(307, '/error'); if (!env.PUBLIC_API_BASE) redirect(307, '/error');
const u = new URL(`lobby/${params.id}`, env.PUBLIC_API_BASE); let u = new URL(`lobby/${params.id}`, env.PUBLIC_API_BASE);
const response = await fetch(u, { const response = await fetch(u, {
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
}); });
if (response.status != 200) { if (response.status != 200) {
redirect(307, '/'); redirect(307, '/');
} }
@@ -28,8 +27,19 @@ export const load: PageServerLoad = async ({ params, fetch, locals: { user } })
players, players,
gameSettings gameSettings
}: { id: string; host: User; players: User[]; gameSettings: Settings } = await response.json(); }: { id: string; host: User; players: User[]; gameSettings: Settings } = await response.json();
console.log('Successful request for lobby');
console.log(id); let playlists: Playlist[] = [];
if (user.email === host.email) {
u = new URL(`user/playlists`, env.PUBLIC_API_BASE);
const res = await fetch(u);
if (response.status != 200) {
console.log('Could not fetch playlists from api');
redirect(307, '/error');
}
playlists = await res.json();
console.log(JSON.stringify(playlists));
}
return { return {
user: user, user: user,
@@ -38,6 +48,7 @@ export const load: PageServerLoad = async ({ params, fetch, locals: { user } })
host, host,
players, players,
gameSettings gameSettings
} },
playlists: playlists
}; };
}; };

View File

@@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import { onMount, onDestroy } from 'svelte'; import { onMount, onDestroy } from 'svelte';
import { wsClient } from '$lib/websocketClient.svelte'; import { wsClient } from '$lib/websocketClient.svelte';
import type { Settings, GameMode, Playlist } from '$lib/types'; import type { Settings, GameMode } from '$lib/types';
import PlayerList from '$lib/components/PlayerList.svelte'; import PlayerList from '$lib/components/PlayerList.svelte';
import GameSettings from '$lib/components/GameSettings.svelte'; import GameSettings from '$lib/components/GameSettings.svelte';
import type { PageProps } from './$types'; import type { PageProps } from './$types';
@@ -24,40 +24,7 @@
{ id: 'speed', name: 'Speed Round' } { id: 'speed', name: 'Speed Round' }
]); ]);
let playlists = $state<Playlist[]>([ let playlists = $state(data.playlists);
{
id: 1,
name: 'Pop Hits 2023',
imageUrl: 'https://example.com/images/pop2023.jpg',
songCount: 25
},
{
id: 2,
name: 'Rock Classics',
imageUrl: 'https://example.com/images/rock.jpg',
songCount: 30
},
{ id: 3, name: '80s Mixtape', imageUrl: 'https://example.com/images/80s.jpg', songCount: 20 },
{
id: 4,
name: 'Movie Soundtracks',
imageUrl: 'https://example.com/images/movies.jpg',
songCount: 15
},
{
id: 5,
name: 'Hip Hop Essentials',
imageUrl: 'https://example.com/images/hiphop.jpg',
songCount: 40
},
{
id: 6,
name: 'Indie Discoveries',
imageUrl: 'https://example.com/images/indie.jpg',
songCount: 35
}
]);
function handleSettingsUpdate(settings: Settings) { function handleSettingsUpdate(settings: Settings) {
// Send updated settings to other players via websocket // Send updated settings to other players via websocket
wsClient.gameSettings = settings; wsClient.gameSettings = settings;
@@ -81,12 +48,12 @@
} }
function leaveLobby() { function leaveLobby() {
wsClient.sendMessage({ wsClient.sendMessage({
type: 'leaveGame', type: 'leaveGame',
player: data.user.email player: data.user.email
}) });
wsClient.disconnect(); wsClient.disconnect();
goto("/"); goto('/');
// In a real app, you'd likely redirect to another page here // In a real app, you'd likely redirect to another page here
} }
@@ -103,7 +70,7 @@
onDestroy(() => { onDestroy(() => {
// Clean up WebSocket connection when component is destroyed // Clean up WebSocket connection when component is destroyed
leaveLobby() leaveLobby();
}); });
</script> </script>