Fix linter errors and types
This commit is contained in:
parent
8360d5d6de
commit
f977fc254a
6 changed files with 33 additions and 26 deletions
|
@ -1,19 +1,25 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import * as Card from '$lib/components/ui/card/index.js';
|
|
||||||
import { dndzone, SHADOW_ITEM_MARKER_PROPERTY_NAME } from 'svelte-dnd-action';
|
|
||||||
import { flip } from 'svelte/animate';
|
import { flip } from 'svelte/animate';
|
||||||
import { expoOut } from 'svelte/easing';
|
import { expoOut } from 'svelte/easing';
|
||||||
import { truncate } from '$lib/utils';
|
|
||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
|
import { truncate } from '$lib/utils';
|
||||||
|
import type { AlbumDataField } from '$lib/types';
|
||||||
|
import {
|
||||||
|
dndzone,
|
||||||
|
SHADOW_ITEM_MARKER_PROPERTY_NAME,
|
||||||
|
type DndEvent,
|
||||||
|
type Item
|
||||||
|
} from 'svelte-dnd-action';
|
||||||
|
import * as Card from '$lib/components/ui/card/index.js';
|
||||||
|
|
||||||
let { items = $bindable(), image = false, type = 'default' } = $props();
|
let { items = $bindable(), image = false, type = 'default' } = $props();
|
||||||
|
|
||||||
const flipDurationMs = 300;
|
const flipDurationMs = 300;
|
||||||
|
|
||||||
function handleDndConsider(e: CustomEvent<any>) {
|
function handleDndConsider(e: CustomEvent<DndEvent<Item>>) {
|
||||||
items = e.detail.items;
|
items = e.detail.items;
|
||||||
}
|
}
|
||||||
function handleDndFinalize(e: CustomEvent<any>) {
|
function handleDndFinalize(e: CustomEvent<DndEvent<Item>>) {
|
||||||
items = e.detail.items;
|
items = e.detail.items;
|
||||||
}
|
}
|
||||||
function transformDraggedElement(draggedEl: HTMLElement | undefined) {
|
function transformDraggedElement(draggedEl: HTMLElement | undefined) {
|
||||||
|
@ -40,7 +46,7 @@
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#snippet card(item, i)}
|
{#snippet card(item: AlbumDataField, i: number)}
|
||||||
{#if image}
|
{#if image}
|
||||||
<img class="aspect-square w-full object-cover" alt="Album Art" src={item.value} />
|
<img class="aspect-square w-full object-cover" alt="Album Art" src={item.value} />
|
||||||
<input type="hidden" name="{type}_{i}" value={item.value} />
|
<input type="hidden" name="{type}_{i}" value={item.value} />
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import type { AlbumData, AlbumSolveState } from '$lib/types';
|
import type { AlbumSolveState } from '$lib/types';
|
||||||
|
|
||||||
class AlbumState {
|
class AlbumState {
|
||||||
private albums: AlbumSolveState[] | undefined = undefined;
|
private albums: AlbumSolveState[] | undefined = undefined;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
export type AlbumData = {
|
export type AlbumData = {
|
||||||
name: AlbumDataField;
|
names: AlbumDataField[];
|
||||||
artists: AlbumDataField;
|
artists: AlbumDataField[];
|
||||||
image: AlbumDataField;
|
images: AlbumDataField[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AlbumDataField = {
|
export type AlbumDataField = {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { shuffleArray } from '$lib/utils';
|
import { shuffleArray } from '$lib/utils';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import type { PageServerLoad } from './$types';
|
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 { albumState } from '$lib/server/AlbumState.svelte';
|
||||||
import { playerState } from '$lib/server/PlayerState.svelte';
|
import { playerState } from '$lib/server/PlayerState.svelte';
|
||||||
|
|
||||||
|
@ -38,15 +38,15 @@ export const load: PageServerLoad = async ({ fetch, locals }) => {
|
||||||
return res.json();
|
return res.json();
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
const albumNames = data.albums.map((album: AlbumData) => ({
|
const albumNames = data.albums.map((album: AlbumSolveState) => ({
|
||||||
id: nanoid(),
|
id: nanoid(),
|
||||||
value: album.name
|
value: album.name
|
||||||
}));
|
}));
|
||||||
const albumImages = data.albums.map((album: AlbumData) => ({
|
const albumImages = data.albums.map((album: AlbumSolveState) => ({
|
||||||
id: nanoid(),
|
id: nanoid(),
|
||||||
value: album.image
|
value: album.image
|
||||||
}));
|
}));
|
||||||
const albumArtists = data.albums.map((album: AlbumData) => ({
|
const albumArtists = data.albums.map((album: AlbumSolveState) => ({
|
||||||
id: nanoid(),
|
id: nanoid(),
|
||||||
value: album.artists
|
value: album.artists
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -7,17 +7,18 @@
|
||||||
import DndGroup from '$lib/components/DNDGroup.svelte';
|
import DndGroup from '$lib/components/DNDGroup.svelte';
|
||||||
import type { PageData } from './$types';
|
import type { PageData } from './$types';
|
||||||
import { enhance } from '$app/forms';
|
import { enhance } from '$app/forms';
|
||||||
|
import type { AlbumData } from '$lib/types';
|
||||||
|
|
||||||
let { data }: { data: PageData; form: FormData } = $props();
|
let { data }: { data: PageData; form: FormData } = $props();
|
||||||
|
|
||||||
let loading = $state(false);
|
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
|
// Used when user answers wrong and no new data comes in
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (data.streamed?.albums) {
|
if (data.streamed?.albums) {
|
||||||
data.streamed.albums.then((data) => {
|
data.streamed.albums.then((data) => {
|
||||||
oldAlbums = data;
|
oldAlbums = data as AlbumData;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -38,11 +39,11 @@
|
||||||
</div>
|
</div>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
|
|
||||||
{#snippet playArea(albums, placeholder = false)}
|
{#snippet playArea(albums: AlbumData | undefined, placeholder = false)}
|
||||||
{#if placeholder}
|
{#if placeholder}
|
||||||
{#each { length: 2 } as _}
|
{#each { length: 2 }}
|
||||||
<section class="grid grid-cols-3 items-center gap-14">
|
<section class="grid grid-cols-3 items-center gap-14">
|
||||||
{#each { length: 3 } as _}
|
{#each { length: 3 }}
|
||||||
<Skeleton class="h-[5.25rem] w-full rounded-xl " />
|
<Skeleton class="h-[5.25rem] w-full rounded-xl " />
|
||||||
{/each}
|
{/each}
|
||||||
</section>
|
</section>
|
||||||
|
@ -50,11 +51,11 @@
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
<section class="grid grid-cols-3 items-center gap-14">
|
<section class="grid grid-cols-3 items-center gap-14">
|
||||||
{#each { length: 3 } as _}
|
{#each { length: 3 }}
|
||||||
<Skeleton class="aspect-square h-auto max-w-full rounded-xl object-cover" />
|
<Skeleton class="aspect-square h-auto max-w-full rounded-xl object-cover" />
|
||||||
{/each}
|
{/each}
|
||||||
</section>
|
</section>
|
||||||
{:else}
|
{:else if albums}
|
||||||
<DndGroup items={albums.names} type="names"></DndGroup>
|
<DndGroup items={albums.names} type="names"></DndGroup>
|
||||||
<Separator />
|
<Separator />
|
||||||
<DndGroup items={albums.artists} type="artists"></DndGroup>
|
<DndGroup items={albums.artists} type="artists"></DndGroup>
|
||||||
|
@ -91,7 +92,7 @@
|
||||||
</AlertDialog.Content>
|
</AlertDialog.Content>
|
||||||
</AlertDialog.Root>
|
</AlertDialog.Root>
|
||||||
|
|
||||||
<header class="font-title mb-24 flex flex-col items-center">
|
<header class="mb-24 flex flex-col items-center font-title">
|
||||||
<h1 class="mb-1 scroll-m-20 text-6xl font-extrabold tracking-tight lg:text-7xl">Paku biiti</h1>
|
<h1 class="mb-1 scroll-m-20 text-6xl font-extrabold tracking-tight lg:text-7xl">Paku biiti</h1>
|
||||||
<p class="text-2xl font-semibold text-muted-foreground">
|
<p class="text-2xl font-semibold text-muted-foreground">
|
||||||
Lohista kokku õiged albumi <span class="text-red-600 dark:text-red-400">nimed</span>,
|
Lohista kokku õiged albumi <span class="text-red-600 dark:text-red-400">nimed</span>,
|
||||||
|
@ -108,9 +109,9 @@
|
||||||
>
|
>
|
||||||
{#if data?.streamed?.albums}
|
{#if data?.streamed?.albums}
|
||||||
{#await data.streamed.albums}
|
{#await data.streamed.albums}
|
||||||
{@render playArea({}, true)}
|
{@render playArea(undefined, true)}
|
||||||
{:then albums}
|
{:then albums}
|
||||||
{@render playArea(albums)}
|
{@render playArea(albums as AlbumData)}
|
||||||
{/await}
|
{/await}
|
||||||
{:else}
|
{:else}
|
||||||
{@render playArea(oldAlbums)}
|
{@render playArea(oldAlbums)}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<meta property="og:image" content={baseURL + '/favicon.svg'} />
|
<meta property="og:image" content={baseURL + '/favicon.svg'} />
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<header class="font-title mb-24 flex flex-col items-center">
|
<header class="mb-24 flex flex-col items-center font-title">
|
||||||
<h1 class="mb-1 scroll-m-20 text-6xl font-extrabold tracking-tight lg:text-7xl">
|
<h1 class="mb-1 scroll-m-20 text-6xl font-extrabold tracking-tight lg:text-7xl">
|
||||||
stuff.kasterpalu.ee
|
stuff.kasterpalu.ee
|
||||||
</h1>
|
</h1>
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
<main class="grid w-full max-w-4xl justify-items-center">
|
<main class="grid w-full max-w-4xl justify-items-center">
|
||||||
{#each Object.entries(games) as [href, { image, name }]}
|
{#each Object.entries(games) as [href, { image, name }]}
|
||||||
<a
|
<a
|
||||||
class="shadow-sharp flex aspect-[4/1] w-full max-w-sm items-center justify-center rounded-xl border-2 border-current bg-contain bg-no-repeat transition-shadow transition-transform"
|
class="shadow-sharp flex aspect-[4/1] w-full max-w-sm items-center justify-center rounded-xl border-2 border-current bg-contain bg-no-repeat transition-all"
|
||||||
style="background-image: url('{image}')"
|
style="background-image: url('{image}')"
|
||||||
draggable="false"
|
draggable="false"
|
||||||
{href}
|
{href}
|
||||||
|
|
Loading…
Add table
Reference in a new issue