From 065f517d54efaa001dcf7fe7c27e54182450436d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9o?= <43091603+glazk0@users.noreply.github.com>
Date: Fri, 21 Apr 2023 17:03:34 +0200
Subject: [PATCH] Added other filter & animations
---
app/dashboard/puzzles/page.tsx | 4 ++--
lib/puzzles.ts | 3 ++-
ui/Puzzles.tsx | 17 +++++++++++++++--
ui/Select.tsx | 2 +-
ui/dashboard/Sidenav.tsx | 17 ++++++++++-------
5 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/app/dashboard/puzzles/page.tsx b/app/dashboard/puzzles/page.tsx
index 62bef6c..3a37113 100644
--- a/app/dashboard/puzzles/page.tsx
+++ b/app/dashboard/puzzles/page.tsx
@@ -20,10 +20,10 @@ export default async function Page() {
}
return (
-
+
);
}
diff --git a/lib/puzzles.ts b/lib/puzzles.ts
index 570162d..c96eb73 100644
--- a/lib/puzzles.ts
+++ b/lib/puzzles.ts
@@ -2,7 +2,8 @@ export const getChapters = async ({ token }: { token: string }): Promise {
if (filter && filterChapter) {
- console.log(filter);
+ if (filter === 'completed' || filter === 'no-completed') {
+ return data
+ ?.find((chapter) => chapter.id === filterChapter)
+ ?.puzzles.filter((puzzle) => {
+ if (filter === 'completed') {
+ return puzzle!.score;
+ }
+ return !puzzle!.score;
+ })
+ .map((puzzle) => puzzle);
+ }
return data
?.find((chapter) => chapter.id === filterChapter)
?.puzzles.filter((puzzle) => puzzle!.tags!.some((tag) => tag.name === filter))
@@ -193,7 +203,7 @@ function PuzzleProp({ puzzle, chapter }: { puzzle: Puzzle; chapter: Chapter }) {
return (
tag.name.toLowerCase() === 'easy'),
'border-yellow-600/30': puzzle.tags?.find((tag) => tag.name.toLowerCase() === 'medium'),
@@ -284,6 +294,9 @@ function FilterChapter({
return { title: t!.name, value: t!.name };
}) as { title: string; value: string }[];
+
+ options?.unshift({ title: 'Pas encore terminé', value: 'no-completed' });
+ options?.unshift({ title: 'Terminés', value: 'completed' });
options?.unshift({ title: 'Tout les puzzles', value: '' });
setFilterChapter(chapter.id);
diff --git a/ui/Select.tsx b/ui/Select.tsx
index da9a6eb..c2af9eb 100644
--- a/ui/Select.tsx
+++ b/ui/Select.tsx
@@ -16,7 +16,7 @@ const Select = forwardRef<