-
-
{chapter.name}
-
+
+
{data.chapter.name}
-
- {#each chapter.puzzles as puzzle}
+
+ {#each data.chapter.puzzles as puzzle}
{/each}
+ {#if data.chapter.puzzles.length > 1}
+
+ {/if}
-
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 edb0094..8c9f50f 100644
--- a/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.server.ts
+++ b/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.server.ts
@@ -1,10 +1,26 @@
import { API_URL } from '$env/static/private';
-import { error, redirect, type Actions } from '@sveltejs/kit';
+import { error, redirect, type Actions, fail } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import type Puzzle from '$lib/components/Puzzle.svelte';
import type { Chapter } from '$lib/types';
+import { superValidate } from 'sveltekit-superforms/server';
+import { z } from 'zod';
+
+const puzzleSchema = z.object({
+ // answer: z.string().trim(),
+ // answer need to be filled
+ answer: z
+ .string({
+ required_error: 'Réponse manquante'
+ })
+ .refine((val) => val.trim() !== '', {
+ message: 'Réponse manquante'
+ }),
+ file: z.any().optional()
+});
+
export const load = (async ({ parent, fetch, cookies, params: { chapterId, puzzleId } }) => {
await parent();
@@ -51,42 +67,14 @@ export const load = (async ({ parent, fetch, cookies, params: { chapterId, puzzl
}
return {
- puzzle: puzzle as Puzzle
+ puzzle: puzzle as Puzzle,
+ url: `${API_URL}/puzzleResponse/${puzzleId}`,
+ session
};
}) satisfies PageServerLoad;
export const actions = {
- default: async (event) => {
- const { id } = event.params;
-
- const data = await event.request.formData();
-
- const res = await fetch(`${API_URL}/puzzleResponse/${id}`, {
- method: 'POST',
- headers: {
- Authorization: `Bearer ${event.cookies.get('session')}`
- },
- body: data
- });
-
- return {
- success: res.ok
- };
-
- // throw redirect(303, `/dashboard/puzzles/${id}`);
-
- // if (res.ok) {
- // const token = res.headers.get('Authorization')?.split(' ')[1];
-
- // if (!token) throw new Error('No token found');
-
- // event.cookies.set('session', token, {
- // path: '/'
- // });
-
- // throw redirect(303, '/dashboard');
- // }
-
- // throw redirect(303, '/sign-in');
+ default: async ({ params, request, cookies }) => {
+ throw redirect(303, `/dashboard/chapters/${params.chapterId}/puzzle/${params.puzzleId}`);
}
} satisfies Actions;
diff --git a/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.svelte b/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.svelte
index 66d57d6..170c2f2 100644
--- a/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.svelte
+++ b/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.svelte
@@ -1,16 +1,33 @@