Feat last event & disabled send back (for now) #15
4 changed files with 34 additions and 37 deletions
|
@ -11,7 +11,7 @@ export const load = (async ({ fetch, cookies, locals: { user } }) => {
|
|||
|
||||
const session = cookies.get('session');
|
||||
|
||||
let res = await fetch(`${API_URL}/chapters`, {
|
||||
const res = await fetch(`${API_URL}/chapters`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${session}`
|
||||
}
|
||||
|
@ -25,38 +25,10 @@ export const load = (async ({ fetch, cookies, locals: { user } }) => {
|
|||
|
||||
const chapters: Chapter[] = await res.json();
|
||||
|
||||
const lastChapter = chapters.filter((chapter) => chapter.show).pop();
|
||||
|
||||
if (!lastChapter) {
|
||||
return {
|
||||
daily: null
|
||||
};
|
||||
}
|
||||
|
||||
res = await fetch(`${API_URL}/chapter/${lastChapter.id}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${session}`
|
||||
}
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
return {
|
||||
daily: {
|
||||
chapter: lastChapter,
|
||||
puzzle: null
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const chapter = (await res.json()) as Chapter;
|
||||
|
||||
const lastPuzzle = chapter.puzzles.filter((puzzle) => puzzle.show).pop();
|
||||
const lastChapter = chapters.filter((chapter) => chapter.start && chapter.end).pop();
|
||||
|
||||
return {
|
||||
title: 'Dashboard',
|
||||
daily: {
|
||||
chapter: lastChapter,
|
||||
puzzle: lastPuzzle
|
||||
}
|
||||
event: lastChapter,
|
||||
};
|
||||
}) satisfies PageServerLoad;
|
||||
|
|
|
@ -22,7 +22,32 @@
|
|||
<Card title="Badges obtenus" data={user?.badges?.length ?? 'Aucun'} />
|
||||
<Card title="Rang actuel" data={user?.rank ?? 'Non classé'} />
|
||||
</div>
|
||||
{#if data.daily && data.daily.puzzle}
|
||||
{#if data.event}
|
||||
<header>
|
||||
<h1 class="text-lg font-semibold">Événement en cours ou à venir</h1>
|
||||
<p class="text-muted-foreground">
|
||||
Partipiez à l'événement en équipe en résolvant des puzzles
|
||||
</p>
|
||||
</header>
|
||||
<div
|
||||
class="flex items-center justify-between gap-4 rounded border border-primary bg-card px-4 py-2"
|
||||
>
|
||||
<div class="flex w-full flex-col justify-between md:flex-row md:items-center md:gap-4">
|
||||
<span class="text-lg font-semibold">{data.event.name}</span>
|
||||
{#if data.event.start && data.event.end}
|
||||
<span class="text-muted-foreground">
|
||||
{new Date(data.event.start).toLocaleDateString()} - {new Date(
|
||||
data.event.end
|
||||
).toLocaleDateString()}
|
||||
</span>
|
||||
{:else}
|
||||
<span class="text-muted-foreground">Aucune date</span>
|
||||
{/if}
|
||||
</div>
|
||||
<Button href="/chapters/{data.event.id}">Participer</Button>
|
||||
</div>
|
||||
{/if}
|
||||
<!-- {#if data.daily && data.daily.puzzle}
|
||||
<header>
|
||||
<h1 class="text-lg font-semibold">Puzzle du jour</h1>
|
||||
<p class="text-muted-foreground">
|
||||
|
@ -42,7 +67,7 @@
|
|||
{data.daily.puzzle.score ? 'Voir' : 'Jouer'}
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
{/if} -->
|
||||
<div class="grid grid-cols-1 gap-4">
|
||||
<div class="flex flex-col gap-4">
|
||||
<header>
|
||||
|
|
|
@ -41,8 +41,8 @@ export const actions = {
|
|||
|
||||
if (res.ok) {
|
||||
return {
|
||||
form
|
||||
}
|
||||
success: true
|
||||
};
|
||||
}
|
||||
|
||||
if (res.status === 400) {
|
||||
|
|
|
@ -163,9 +163,9 @@
|
|||
Continuer
|
||||
</Form.Button>
|
||||
|
||||
<Button variant="link" formaction="?/register" on:click={() => toast('Code renvoyé')}>
|
||||
<!-- <Button variant="link" formaction="?/register" on:click={() => toast('Code renvoyé')}>
|
||||
Renvoyer le code
|
||||
</Button>
|
||||
</Button> -->
|
||||
</form>
|
||||
{:else}
|
||||
<h1 class="mx-auto text-xl font-bold">Inscription</h1>
|
||||
|
|
Loading…
Add table
Reference in a new issue