From bf6c76554f03e1554057095a7d3449d97f46473b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o?= <43091603+glazk0@users.noreply.github.com> Date: Sat, 9 Sep 2023 21:23:58 +0200 Subject: [PATCH] fix: chapter --- src/app.css | 6 +-- src/lib/components/Chapter.svelte | 51 ++++++++++--------- src/lib/stores/Register.ts | 19 ------- src/lib/types/Database.ts | 3 +- .../chapters/[chapterId]/+page.server.ts | 4 ++ .../chapters/[chapterId]/+page.svelte | 48 ----------------- .../puzzle/[puzzleId]/+page.server.ts | 12 +++-- .../puzzle/[puzzleId]/+page.svelte | 5 +- src/routes/sign-up/+page.svelte | 23 ++++----- 9 files changed, 58 insertions(+), 113 deletions(-) delete mode 100644 src/lib/stores/Register.ts diff --git a/src/app.css b/src/app.css index eafe054..ab934ea 100644 --- a/src/app.css +++ b/src/app.css @@ -1,6 +1,6 @@ -@tailwind base; -@tailwind components; -@tailwind utilities; +@import 'tailwindcss/base'; +@import 'tailwindcss/components'; +@import 'tailwindcss/utilities'; @font-face { font-family: 'Karrik'; diff --git a/src/lib/components/Chapter.svelte b/src/lib/components/Chapter.svelte index 5754117..d6f1afe 100644 --- a/src/lib/components/Chapter.svelte +++ b/src/lib/components/Chapter.svelte @@ -9,31 +9,34 @@
  • - -
    -

    - {chapter.name} -

    - -
    - - + {#if chapter.show} +
    +
    +

    + {chapter.name} +

    +
    + + + +
    + {:else} + +
    +

    + {chapter.name} +

    +
    - + {/if}
  • diff --git a/src/lib/stores/Register.ts b/src/lib/stores/Register.ts deleted file mode 100644 index 763ee86..0000000 --- a/src/lib/stores/Register.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { browser } from '$app/environment'; -import { writable } from 'svelte/store'; - -const defaultValue = false; -const initialValue = browser ? window.localStorage.getItem('register') === 'true' : defaultValue; - -const register = writable(initialValue); - -register.subscribe((value) => { - if (browser) { - window.localStorage.setItem('register', value ? 'true' : 'false'); - } -}); - -export function resetRegister() { - register.set(defaultValue); -} - -export default register; diff --git a/src/lib/types/Database.ts b/src/lib/types/Database.ts index 8b85147..dff9ef9 100644 --- a/src/lib/types/Database.ts +++ b/src/lib/types/Database.ts @@ -47,8 +47,7 @@ export interface Chapter { id: number; name: string; puzzles: Puzzle[]; - startDate?: string; - endDate?: string; + show?: boolean; } export interface Tag { diff --git a/src/routes/dashboard/chapters/[chapterId]/+page.server.ts b/src/routes/dashboard/chapters/[chapterId]/+page.server.ts index 3476e9a..759c346 100644 --- a/src/routes/dashboard/chapters/[chapterId]/+page.server.ts +++ b/src/routes/dashboard/chapters/[chapterId]/+page.server.ts @@ -22,6 +22,10 @@ export const load = (async ({ parent, fetch, cookies, params: { chapterId } }) = const chapter = (await res.json()) as Chapter; + if (!chapter || !chapter.show) { + throw redirect(302, '/dashboard/chapters'); + } + return { chapter }; diff --git a/src/routes/dashboard/chapters/[chapterId]/+page.svelte b/src/routes/dashboard/chapters/[chapterId]/+page.svelte index 9f3b048..787231c 100644 --- a/src/routes/dashboard/chapters/[chapterId]/+page.svelte +++ b/src/routes/dashboard/chapters/[chapterId]/+page.svelte @@ -29,54 +29,6 @@ )} --> -
    - {#if chapter.startDate && chapter.endDate} -
    - - - {new Date(chapter.startDate).toLocaleDateString('fr-FR', { - day: 'numeric', - month: 'long', - year: 'numeric', - hour: 'numeric', - minute: 'numeric' - })}{' '} - -{' '} - {new Date(chapter.endDate).toLocaleDateString('fr-FR', { - day: 'numeric', - month: 'long', - year: 'numeric', - hour: 'numeric', - minute: 'numeric' - })} - -
    - {:else} -
    -
    -
    - {/if} -
    - -
    -