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 8c9f50f..beb07ec 100644 --- a/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.server.ts +++ b/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.server.ts @@ -1,26 +1,10 @@ import { API_URL } from '$env/static/private'; -import { error, redirect, type Actions, fail } from '@sveltejs/kit'; +import { error, redirect, type Actions } 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(); diff --git a/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.svelte b/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.svelte index 54de7d2..d560af5 100644 --- a/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.svelte +++ b/src/routes/dashboard/chapters/[chapterId]/puzzle/[puzzleId]/+page.svelte @@ -5,9 +5,10 @@ import { goto } from '$app/navigation'; import { page } from '$app/stores'; + import { Loader2 } from 'lucide-svelte'; + import { marked, type MarkedOptions } from 'marked'; - import { cn } from '$lib'; import { addToast } from '$lib/components/Toaster.svelte'; import Button from '$lib/components/ui/Button.svelte'; import Input from '$lib/components/ui/Input.svelte'; @@ -17,6 +18,8 @@ $: puzzle = data.puzzle; $: chapterId = $page.params.chapterId; + let submitting = false; + const renderer = new marked.Renderer(); renderer.link = (href, title, text) => { @@ -56,6 +59,8 @@ method="POST" enctype="multipart/form-data" use:enhance={async ({ formData, cancel }) => { + submitting = true; + if (formData.get('answer') === '') { addToast({ data: { @@ -112,6 +117,8 @@ }); } + submitting = false; + return async ({ result }) => { if (result.type === 'redirect') { goto(result.location, { @@ -125,19 +132,22 @@