diff --git a/src/lib/components/Game.svelte b/src/lib/components/Game.svelte index b5045f1..8644d8f 100644 --- a/src/lib/components/Game.svelte +++ b/src/lib/components/Game.svelte @@ -3,9 +3,10 @@ interface GameProps { game?: SerializableGameInfo + type: 'steam' | 'psn' } - let { game = undefined }: GameProps = $props() + let { game = undefined, type }: GameProps = $props() let isHovering = $state(false) @@ -21,12 +22,17 @@ scale.set(1) } }) + + const url = + type === 'steam' + ? `https://store.steampowered.com/app/${game?.id}` + : `https://store.playstation.com/en-us/product/${game?.id}/`
{#if game} (isHovering = true)} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 056314d..513d1b0 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -11,7 +11,7 @@ export let data: PageData - $: ({ albums, games, error } = data) + $: ({ albums, steamGames, psnGames, error } = data) @@ -19,7 +19,9 @@

- + @@ -70,10 +72,22 @@
- {#if games.length > 0} + {#if steamGames && steamGames.length > 0}
    - {#each games.slice(0, 3) as game} - + {#each steamGames.slice(0, 3) as game} + + {/each} +
+ {:else} +

Loading games...

+ {/if} +
+ +
+ {#if psnGames && psnGames.length > 0} +
    + {#each psnGames.slice(0, 3) as game} + {/each}
{:else} diff --git a/src/routes/+page.ts b/src/routes/+page.ts index d93b1e5..1014991 100644 --- a/src/routes/+page.ts +++ b/src/routes/+page.ts @@ -1,14 +1,19 @@ import type { PageLoad } from './$types' import type { Album } from '$lib/types/lastfm' -import type { GameInfoExtended, UserPlaytime } from 'steamapi' +import type { RecentlyPlayedGame } from 'psn-api' export const load: PageLoad = async ({ fetch }) => { try { - const [albums, games] = await Promise.all([fetchRecentAlbums(fetch), fetchRecentGames(fetch)]) - console.log(games[0]) + const [albums, steamGames, psnGames] = await Promise.all([ + fetchRecentAlbums(fetch), + fetchRecentSteamGames(fetch), + fetchRecentPSNGames(fetch) + ]) + return { albums, - games + steamGames: steamGames, + psnGames: psnGames } } catch (err) { console.error('Error fetching data:', err) @@ -27,10 +32,18 @@ async function fetchRecentAlbums(fetch: typeof window.fetch): Promise { return musicData.albums } -async function fetchRecentGames(fetch: typeof window.fetch): Promise { +async function fetchRecentSteamGames(fetch: typeof window.fetch): Promise { const response = await fetch('/api/steam') if (!response.ok) { throw new Error(`Failed to fetch recent game: ${response.status}`) } return await response.json() } + +async function fetchRecentPSNGames(fetch: typeof window.fetch): Promise { + const response = await fetch('/api/psn') + if (!response.ok) { + throw new Error(`Failed to fetch recent game: ${response.status}`) + } + return await response.json() +}