diff --git a/src/routes/dashboard/+page.server.ts b/src/routes/dashboard/+page.server.ts new file mode 100644 index 0000000..7f85f49 --- /dev/null +++ b/src/routes/dashboard/+page.server.ts @@ -0,0 +1,59 @@ +import { API_URL } from '$env/static/private'; + +import type { PageServerLoad } from './$types'; + +import type { Chapter } from '$lib/types'; + +export const load = (async ({ parent, fetch, cookies }) => { + await parent(); + + const session = cookies.get('session'); + + let res = await fetch(`${API_URL}/chapters`, { + headers: { + Authorization: `Bearer ${session}` + } + }); + + if (!res.ok) { + return { + daily: null + }; + } + + const chapters = (await res.json()) as Chapter[]; + + 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(); + + return { + daily: { + chapter: lastChapter, + puzzle: lastPuzzle + } + }; +}) satisfies PageServerLoad; diff --git a/src/routes/dashboard/+page.svelte b/src/routes/dashboard/+page.svelte index c30b98f..69acc45 100644 --- a/src/routes/dashboard/+page.svelte +++ b/src/routes/dashboard/+page.svelte @@ -1,27 +1,51 @@ -
+
+ {#if data.daily && data.daily.puzzle} +
+
+ {data.daily.chapter.name} + + {data.daily.puzzle.name} ({data.daily.puzzle.score ?? '?'}/{data.daily.puzzle.scoreMax}) + +
+
+ +
+
+ {/if}

Tableau de bord

Ceci est la page d'accueil du dashboard

-
+
-
+

Derniers puzzles

diff --git a/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.server.ts b/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.server.ts index fbb21f2..d4531b6 100644 --- a/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.server.ts +++ b/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.server.ts @@ -30,8 +30,6 @@ export const load = (async ({ parent, fetch, cookies, params: { chapterId, puzzl throw redirect(303, `/dashboard/chapters`); } - console.log(chapter); - if ( !chapter.puzzles.some((puzzle) => puzzle.id === parseInt(puzzleId)) || !chapter.puzzles.find((puzzle) => puzzle.id === parseInt(puzzleId))?.show @@ -51,8 +49,6 @@ export const load = (async ({ parent, fetch, cookies, params: { chapterId, puzzl const puzzle = await res.json(); - console.log(puzzle); - if (!puzzle) { throw error(404, 'Puzzle not found'); } @@ -65,7 +61,7 @@ export const load = (async ({ parent, fetch, cookies, params: { chapterId, puzzl }) satisfies PageServerLoad; export const actions = { - default: async ({ params, request, cookies }) => { + default: async ({ params }) => { throw redirect(303, `/dashboard/chapters/${params.chapterId}/puzzle/${params.puzzleId}`); } } satisfies Actions; diff --git a/src/routes/dashboard/leaderboard/+page.svelte b/src/routes/dashboard/leaderboard/+page.svelte index 2e88c25..94d164f 100644 --- a/src/routes/dashboard/leaderboard/+page.svelte +++ b/src/routes/dashboard/leaderboard/+page.svelte @@ -35,7 +35,7 @@

- {player.pseudo} + {player.pseudo}