2025-01-19 05:24:56 +02:00
|
|
|
<script lang="ts">
|
2025-01-21 13:46:16 +02:00
|
|
|
import { Separator } from '$lib/components/ui/separator/index.js';
|
2025-01-21 13:10:47 +02:00
|
|
|
import LoaderCircle from 'lucide-svelte/icons/loader-circle';
|
2025-01-19 05:24:56 +02:00
|
|
|
import { Button } from '$lib/components/ui/button/index.js';
|
2025-01-21 11:42:52 +02:00
|
|
|
import * as AlertDialog from '$lib/components/ui/alert-dialog/index.js';
|
|
|
|
import { Skeleton } from '$lib/components/ui/skeleton/index.js';
|
2025-01-19 05:24:56 +02:00
|
|
|
import DndGroup from '$lib/components/DNDGroup.svelte';
|
|
|
|
import type { PageData } from './$types';
|
|
|
|
import { enhance } from '$app/forms';
|
|
|
|
|
2025-01-21 11:42:52 +02:00
|
|
|
let { data, form }: { data: PageData; form: FormData } = $props();
|
|
|
|
|
|
|
|
let loading = $state(true);
|
2025-01-21 13:10:47 +02:00
|
|
|
let oldAlbums: SpotifyApi.AlbumObjectSimplified[] = $state([]);
|
2025-01-21 11:42:52 +02:00
|
|
|
|
|
|
|
$effect(() => {
|
2025-01-21 13:10:47 +02:00
|
|
|
// this is a hack to disable grayscale, please ignore
|
|
|
|
// eslint-disable-next-line no-constant-binary-expression
|
|
|
|
loading = false && form?.success;
|
2025-01-21 11:42:52 +02:00
|
|
|
});
|
|
|
|
|
2025-01-21 13:10:47 +02:00
|
|
|
// Used when user answers wrong and no new data comes in
|
|
|
|
$effect(() => {
|
|
|
|
if (data.streamed?.albums) {
|
|
|
|
data.streamed.albums.then((data) => {
|
|
|
|
oldAlbums = data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2025-01-19 05:24:56 +02:00
|
|
|
</script>
|
|
|
|
|
2025-01-21 13:10:47 +02:00
|
|
|
{#snippet footer(loading: boolean)}
|
2025-01-21 15:22:19 +02:00
|
|
|
<div class="mt-8 flex items-center justify-evenly">
|
|
|
|
<p class="font-title text-lg font-semibold">Skoor: {data.stage}</p>
|
2025-01-21 13:10:47 +02:00
|
|
|
{#if loading}
|
2025-01-21 15:22:19 +02:00
|
|
|
<Button disabled class="min-w-[4.5rem]">
|
2025-01-21 13:10:47 +02:00
|
|
|
<LoaderCircle class="animate-spin" />
|
2025-01-21 15:22:19 +02:00
|
|
|
Oota
|
2025-01-21 13:10:47 +02:00
|
|
|
</Button>
|
|
|
|
{:else}
|
2025-01-21 15:22:19 +02:00
|
|
|
<Button type="submit" class="min-w-[4.5rem]">Saada</Button>
|
2025-01-21 13:10:47 +02:00
|
|
|
{/if}
|
2025-01-21 15:22:19 +02:00
|
|
|
<p class="font-title text-lg font-semibold">Parim: {data.highscore}</p>
|
2025-01-21 13:10:47 +02:00
|
|
|
</div>
|
|
|
|
{/snippet}
|
|
|
|
|
2025-01-21 11:42:52 +02:00
|
|
|
<AlertDialog.Root open={form?.solved === false}>
|
|
|
|
<AlertDialog.Content>
|
|
|
|
<AlertDialog.Header>
|
|
|
|
<AlertDialog.Title>
|
|
|
|
{#if data?.highscore && data?.stage && data.highscore === data.stage}
|
2025-01-21 13:10:47 +02:00
|
|
|
Uus parim tulemus!
|
2025-01-21 11:42:52 +02:00
|
|
|
{:else}
|
2025-01-21 13:10:47 +02:00
|
|
|
Seekord ei vedanud
|
2025-01-21 11:42:52 +02:00
|
|
|
{/if}
|
|
|
|
</AlertDialog.Title>
|
|
|
|
<AlertDialog.Description>
|
|
|
|
{#if data.stage === 0}
|
2025-01-21 13:46:16 +02:00
|
|
|
Põrusid esimesel katsel.
|
2025-01-21 11:42:52 +02:00
|
|
|
{:else}
|
2025-01-21 13:10:47 +02:00
|
|
|
Vastasid õigesti <strong>{data.stage} korda.</strong>
|
2025-01-21 11:42:52 +02:00
|
|
|
{/if}
|
|
|
|
</AlertDialog.Description>
|
|
|
|
</AlertDialog.Header>
|
|
|
|
<AlertDialog.Footer>
|
|
|
|
<form action="?/restart" method="POST" use:enhance>
|
2025-01-21 13:10:47 +02:00
|
|
|
<AlertDialog.Action type="submit">Uuesti</AlertDialog.Action>
|
2025-01-21 11:42:52 +02:00
|
|
|
</form>
|
|
|
|
</AlertDialog.Footer>
|
|
|
|
</AlertDialog.Content>
|
|
|
|
</AlertDialog.Root>
|
|
|
|
|
|
|
|
<form
|
|
|
|
action="?/submit"
|
|
|
|
method="POST"
|
|
|
|
use:enhance
|
2025-01-21 15:22:19 +02:00
|
|
|
class="grid w-full gap-6 transition-all {loading || data?.playing === false ? 'grayscale' : ''}"
|
2025-01-21 11:42:52 +02:00
|
|
|
>
|
2025-01-21 13:10:47 +02:00
|
|
|
{#if data?.streamed?.albums}
|
|
|
|
{#await data.streamed.albums}
|
|
|
|
{#each { length: 2 } as _}
|
2025-01-21 13:46:16 +02:00
|
|
|
<section class="grid grid-cols-3 items-center gap-14">
|
2025-01-21 13:10:47 +02:00
|
|
|
{#each { length: 3 } as _}
|
2025-01-21 15:22:19 +02:00
|
|
|
<Skeleton class="h-[5.25rem] w-full rounded-xl " />
|
2025-01-21 13:10:47 +02:00
|
|
|
{/each}
|
|
|
|
</section>
|
2025-01-21 13:46:16 +02:00
|
|
|
<Separator />
|
2025-01-21 13:10:47 +02:00
|
|
|
{/each}
|
|
|
|
|
2025-01-21 13:46:16 +02:00
|
|
|
<section class="grid grid-cols-3 items-center gap-14">
|
2025-01-21 11:42:52 +02:00
|
|
|
{#each { length: 3 } as _}
|
2025-01-21 13:10:47 +02:00
|
|
|
<Skeleton class="aspect-square h-auto max-w-full rounded-xl object-cover" />
|
2025-01-21 11:42:52 +02:00
|
|
|
{/each}
|
|
|
|
</section>
|
|
|
|
|
2025-01-21 13:10:47 +02:00
|
|
|
{@render footer(true)}
|
|
|
|
{:then albums}
|
2025-01-21 11:42:52 +02:00
|
|
|
<DndGroup items={albums.names} type="names"></DndGroup>
|
2025-01-21 13:46:16 +02:00
|
|
|
<Separator />
|
2025-01-21 11:42:52 +02:00
|
|
|
<DndGroup items={albums.artists} type="artists"></DndGroup>
|
2025-01-21 13:46:16 +02:00
|
|
|
<Separator />
|
2025-01-21 11:42:52 +02:00
|
|
|
<DndGroup items={albums.images} image type="images"></DndGroup>
|
2025-01-19 05:24:56 +02:00
|
|
|
|
2025-01-21 13:10:47 +02:00
|
|
|
{@render footer(false)}
|
|
|
|
{/await}
|
|
|
|
{:else}
|
|
|
|
<DndGroup items={oldAlbums.names} type="names"></DndGroup>
|
2025-01-21 13:46:16 +02:00
|
|
|
<Separator />
|
2025-01-21 13:10:47 +02:00
|
|
|
<DndGroup items={oldAlbums.artists} type="artists"></DndGroup>
|
2025-01-21 13:46:16 +02:00
|
|
|
<Separator />
|
2025-01-21 13:10:47 +02:00
|
|
|
<DndGroup items={oldAlbums.images} image type="images"></DndGroup>
|
|
|
|
|
|
|
|
{@render footer(false)}
|
|
|
|
{/if}
|
2025-01-19 05:24:56 +02:00
|
|
|
</form>
|