diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index 074085a..413a419 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -1,10 +1,22 @@ // import { log } from 'console'; -import { listMyPlaylists, listRecPlaylists } from '../lib/server/songs'; +import { listMyPlaylists, listRecPlaylists, getPlaylist } from '../lib/server/songs'; import type { PageServerLoad } from './$types'; export const load: PageServerLoad = async ({ params, parent }) => { let last = undefined const { user } = await parent() + + if (user?.data?.loc) { + try { + const playlist = await getPlaylist(user.data.loc.currentPlaylistId); + if (playlist) { + last = playlist.tracks[user.data.loc.currentSongIndex]; + } + } catch (e) { + console.error("Failed to load last playlist", e); + } + } + let myPlaylists = await listMyPlaylists(user) let recPlaylists = await listRecPlaylists() return { last, myPlaylists, recPlaylists } diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 476529c..3235dfe 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -9,6 +9,9 @@ let { data }: PageProps = $props() console.log(data.recPlaylists) + + const loc = data.user.data.loc + const href = loc?.isFinished && loc?.lastResultId ? `/results/${loc.lastResultId}` : `/song/${data.last?.id}` @@ -18,12 +21,12 @@
{#if data.last} -
+
-
+ {/if}