From f977fc254a21d068d66b641d9baf28582c2d0cfd Mon Sep 17 00:00:00 2001 From: Mihkel Martin Kasterpalu Date: Wed, 22 Jan 2025 14:21:34 +0200 Subject: [PATCH] Fix linter errors and types --- src/lib/components/DNDGroup.svelte | 18 ++++++++++------ src/lib/server/AlbumState.svelte.ts | 2 +- src/lib/types.ts | 6 +++--- .../(singlescreen)/pakubiiti/+page.server.ts | 8 +++---- .../(singlescreen)/pakubiiti/+page.svelte | 21 ++++++++++--------- src/routes/(landing)/+page.svelte | 4 ++-- 6 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/lib/components/DNDGroup.svelte b/src/lib/components/DNDGroup.svelte index f17601c..a2af143 100644 --- a/src/lib/components/DNDGroup.svelte +++ b/src/lib/components/DNDGroup.svelte @@ -1,19 +1,25 @@ -{#snippet card(item, i)} +{#snippet card(item: AlbumDataField, i: number)} {#if image} Album Art diff --git a/src/lib/server/AlbumState.svelte.ts b/src/lib/server/AlbumState.svelte.ts index bafd5b9..c7ac8ba 100644 --- a/src/lib/server/AlbumState.svelte.ts +++ b/src/lib/server/AlbumState.svelte.ts @@ -1,4 +1,4 @@ -import type { AlbumData, AlbumSolveState } from '$lib/types'; +import type { AlbumSolveState } from '$lib/types'; class AlbumState { private albums: AlbumSolveState[] | undefined = undefined; diff --git a/src/lib/types.ts b/src/lib/types.ts index 4571de4..8cf0f73 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -1,7 +1,7 @@ export type AlbumData = { - name: AlbumDataField; - artists: AlbumDataField; - image: AlbumDataField; + names: AlbumDataField[]; + artists: AlbumDataField[]; + images: AlbumDataField[]; }; export type AlbumDataField = { diff --git a/src/routes/(games)/(singlescreen)/pakubiiti/+page.server.ts b/src/routes/(games)/(singlescreen)/pakubiiti/+page.server.ts index 9aad4c7..3015481 100644 --- a/src/routes/(games)/(singlescreen)/pakubiiti/+page.server.ts +++ b/src/routes/(games)/(singlescreen)/pakubiiti/+page.server.ts @@ -1,7 +1,7 @@ import { shuffleArray } from '$lib/utils'; import { nanoid } from 'nanoid'; import type { PageServerLoad } from './$types'; -import type { AlbumData, AlbumSolveState } from '$lib/types'; +import type { AlbumSolveState } from '$lib/types'; import { albumState } from '$lib/server/AlbumState.svelte'; import { playerState } from '$lib/server/PlayerState.svelte'; @@ -38,15 +38,15 @@ export const load: PageServerLoad = async ({ fetch, locals }) => { return res.json(); }) .then((data) => { - const albumNames = data.albums.map((album: AlbumData) => ({ + const albumNames = data.albums.map((album: AlbumSolveState) => ({ id: nanoid(), value: album.name })); - const albumImages = data.albums.map((album: AlbumData) => ({ + const albumImages = data.albums.map((album: AlbumSolveState) => ({ id: nanoid(), value: album.image })); - const albumArtists = data.albums.map((album: AlbumData) => ({ + const albumArtists = data.albums.map((album: AlbumSolveState) => ({ id: nanoid(), value: album.artists })); diff --git a/src/routes/(games)/(singlescreen)/pakubiiti/+page.svelte b/src/routes/(games)/(singlescreen)/pakubiiti/+page.svelte index 53d8438..577a954 100644 --- a/src/routes/(games)/(singlescreen)/pakubiiti/+page.svelte +++ b/src/routes/(games)/(singlescreen)/pakubiiti/+page.svelte @@ -7,17 +7,18 @@ import DndGroup from '$lib/components/DNDGroup.svelte'; import type { PageData } from './$types'; import { enhance } from '$app/forms'; + import type { AlbumData } from '$lib/types'; let { data }: { data: PageData; form: FormData } = $props(); let loading = $state(false); - let oldAlbums: SpotifyApi.AlbumObjectSimplified[] = $state([]); + let oldAlbums: AlbumData | undefined = $state(); // Used when user answers wrong and no new data comes in $effect(() => { if (data.streamed?.albums) { data.streamed.albums.then((data) => { - oldAlbums = data; + oldAlbums = data as AlbumData; }); } }); @@ -38,11 +39,11 @@ {/snippet} -{#snippet playArea(albums, placeholder = false)} +{#snippet playArea(albums: AlbumData | undefined, placeholder = false)} {#if placeholder} - {#each { length: 2 } as _} + {#each { length: 2 }}
- {#each { length: 3 } as _} + {#each { length: 3 }} {/each}
@@ -50,11 +51,11 @@ {/each}
- {#each { length: 3 } as _} + {#each { length: 3 }} {/each}
- {:else} + {:else if albums} @@ -91,7 +92,7 @@ -
+

Paku biiti

Lohista kokku õiged albumi nimed, @@ -108,9 +109,9 @@ > {#if data?.streamed?.albums} {#await data.streamed.albums} - {@render playArea({}, true)} + {@render playArea(undefined, true)} {:then albums} - {@render playArea(albums)} + {@render playArea(albums as AlbumData)} {/await} {:else} {@render playArea(oldAlbums)} diff --git a/src/routes/(landing)/+page.svelte b/src/routes/(landing)/+page.svelte index 309bad8..2af592f 100644 --- a/src/routes/(landing)/+page.svelte +++ b/src/routes/(landing)/+page.svelte @@ -12,7 +12,7 @@ -

+

stuff.kasterpalu.ee

@@ -21,7 +21,7 @@
{#each Object.entries(games) as [href, { image, name }]}