diff --git a/app/dashboard/leaderboard/page.tsx b/app/dashboard/leaderboard/page.tsx
index f2bc96a..6e83730 100644
--- a/app/dashboard/leaderboard/page.tsx
+++ b/app/dashboard/leaderboard/page.tsx
@@ -1,22 +1,4 @@
-import { getScores } from '@/lib/leaderboard';
-import { cn } from '@/lib/utils';
-import Avatar from '@/ui/Avatar';
-import Select from '@/ui/Select';
-
-// TODO: Generate this later
-const scoreColors = ['text-yellow-400', 'text-gray-400', 'text-orange-400'];
-
-// TODO: Generate this later
-const options = [
- { value: '1i1', title: '1I1' },
- { value: '1i2', title: '1I2' },
- { value: '1i3', title: '1I3' },
- { value: '1i4', title: '1I4' },
- { value: '1i5', title: '1I5' },
- { value: '1i6', title: '1I6' },
- { value: '1i7', title: '1I7' },
- { value: '1i8', title: '1I8' }
-];
+import Leaderboard from '@/ui/Leaderboard';
export const metadata = {
title: 'Tableau des scores - Peer-at Code',
@@ -24,49 +6,5 @@ export const metadata = {
};
export default async function Page() {
- // TODO: CSR fetch data for leaderboard (useSWR) to make it more reactive
- const data = await getScores();
- return (
-
-
-
-
-
- {data.map((score, key) => (
-
-
-
-
{key + 1}
-
-
-
{score.pseudo}
-
{score.group}
-
-
-
-
- Puzzles
- {score.completions}
-
-
- Score
- {score.score}
-
-
-
-
- ))}
-
-
-
-
- );
+ return ;
}
diff --git a/app/dashboard/puzzles/[id]/page.tsx b/app/dashboard/puzzles/[id]/page.tsx
index 40704d4..68664a6 100644
--- a/app/dashboard/puzzles/[id]/page.tsx
+++ b/app/dashboard/puzzles/[id]/page.tsx
@@ -23,8 +23,10 @@ export default async function Page({ params }: { params: { id: number } }) {
return ;
}
+// export const dynamicParams = true;
+
// export async function generateStaticParams() {
// const { puzzles } = await getPuzzles();
// // every id is a number, but we need to return a string
-// return puzzles.map((puzzle) => ({ id: puzzle.id.toString() }));
+// return puzzles.flatMap((puzzle) => ({ id: puzzle.id.toString() }));
// }
diff --git a/app/dashboard/puzzles/page.tsx b/app/dashboard/puzzles/page.tsx
index 1e1db4f..29f9ba8 100644
--- a/app/dashboard/puzzles/page.tsx
+++ b/app/dashboard/puzzles/page.tsx
@@ -1,4 +1,3 @@
-import { getPuzzles } from '@/lib/puzzles';
import Puzzles from '@/ui/Puzzles';
export const metadata = {
@@ -6,10 +5,9 @@ export const metadata = {
};
export default async function Page() {
- const data = await getPuzzles();
return (
);
}
diff --git a/lib/hooks/use-leaderboard.ts b/lib/hooks/use-leaderboard.ts
new file mode 100644
index 0000000..fb11515
--- /dev/null
+++ b/lib/hooks/use-leaderboard.ts
@@ -0,0 +1,6 @@
+import useSWR from 'swr';
+import { getScores } from '../leaderboard';
+
+export function useLeaderboard() {
+ return useSWR('leaderboard', () => getScores());
+}
diff --git a/lib/puzzles.ts b/lib/puzzles.ts
index 9505794..5b374d7 100644
--- a/lib/puzzles.ts
+++ b/lib/puzzles.ts
@@ -17,8 +17,6 @@ export const getChapters = async (): Promise => {
chapters = chapters.filter((chapter: Chapter) => chapter.id !== 0);
- console.log(chapters);
-
return chapters as Chapter[];
};
diff --git a/middleware.ts b/middleware.ts
index b7cf541..3c074e8 100644
--- a/middleware.ts
+++ b/middleware.ts
@@ -20,8 +20,6 @@ export async function middleware(req: NextRequest) {
else if (req.nextUrl.pathname.includes('sign') && token)
return NextResponse.redirect(getURL('/dashboard'));
- res.headers.set('Authorization', `Bearer ${token}`);
-
return res;
}
diff --git a/styles/globals.css b/styles/globals.css
index 9ed3a33..fe01a95 100644
--- a/styles/globals.css
+++ b/styles/globals.css
@@ -5,6 +5,5 @@
@layer components {
.console {
@apply relative top-0.5 inline-block;
- /* make it hidden then visible every seconde */
}
}
diff --git a/tailwind.config.js b/tailwind.config.js
index a342765..b160c52 100644
--- a/tailwind.config.js
+++ b/tailwind.config.js
@@ -29,8 +29,8 @@ module.exports = {
0: 'hsl(258deg 8% 100%)'
},
brand: {
- DEFAULT: '#1c56cb',
- accent: '#236bfe'
+ DEFAULT: '#5049ca',
+ accent: '#913fb6'
},
success: {
DEFAULT: 'hsl(104deg 39% 59%)',
@@ -55,11 +55,6 @@ module.exports = {
highlight: {
primary: 'hsl(258deg 15% 17%)',
secondary: 'hsl(258deg 10% 46%)'
- },
- product: {
- ignite: 'hsl(8deg 89% 57%)',
- pipe: 'hsl(214deg 100% 58%)',
- channels: 'hsl(46deg 74% 51%)'
}
},
backgroundColor: {
diff --git a/tsconfig.json b/tsconfig.json
index 597f483..8eac0d6 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -14,6 +14,7 @@
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
+ "downlevelIteration": true,
"plugins": [
{
"name": "next"
diff --git a/ui/Button.tsx b/ui/Button.tsx
index 2ec101f..270ce0f 100644
--- a/ui/Button.tsx
+++ b/ui/Button.tsx
@@ -14,7 +14,7 @@ const Button = forwardRef<
{
'bg-highlight-primary hover:bg-highlight-primary/60': kind === 'default',
'bg-error hover:bg-error/60': kind === 'danger',
- 'bg-brand hover:bg-brand/60': kind === 'brand'
+ 'bg-gradient-to-tl from-brand to-brand-accent hover:bg-opacity-80': kind === 'brand'
},
className
)}
diff --git a/ui/Input.tsx b/ui/Input.tsx
index cea1335..dd4f0d5 100644
--- a/ui/Input.tsx
+++ b/ui/Input.tsx
@@ -14,7 +14,7 @@ const Input = forwardRef<
diff --git a/ui/Leaderboard.tsx b/ui/Leaderboard.tsx
new file mode 100644
index 0000000..504f4a1
--- /dev/null
+++ b/ui/Leaderboard.tsx
@@ -0,0 +1,79 @@
+'use client';
+
+import { useLeaderboard } from '@/lib/hooks/use-leaderboard';
+import { cn } from '@/lib/utils';
+import Avatar from './Avatar';
+import Select from './Select';
+
+// TODO: Generate this later
+const scoreColors = ['text-yellow-400', 'text-gray-400', 'text-orange-400'];
+
+// TODO: Generate this later
+export const options = [
+ { value: '1i1', title: '1I1' },
+ { value: '1i2', title: '1I2' },
+ { value: '1i3', title: '1I3' },
+ { value: '1i4', title: '1I4' },
+ { value: '1i5', title: '1I5' },
+ { value: '1i6', title: '1I6' },
+ { value: '1i7', title: '1I7' },
+ { value: '1i8', title: '1I8' }
+];
+
+export default function Leaderboard() {
+ const { data, isLoading } = useLeaderboard();
+ return (
+
+
+
+
+
+ {(!isLoading &&
+ data?.map((score, key) => (
+
+
+
+
{key + 1}
+
+
+
{score.pseudo}
+
{score.group}
+
+
+
+
+ Puzzles
+ {score.completions}
+
+
+ Score
+ {score.score}
+
+
+
+
+ ))) ||
+ [...Array(20).keys()].map((i) => (
+
+ ))}
+
+
+
+
+ );
+}
diff --git a/ui/Puzzle.tsx b/ui/Puzzle.tsx
index 709f55f..ae66e31 100644
--- a/ui/Puzzle.tsx
+++ b/ui/Puzzle.tsx
@@ -3,6 +3,7 @@
import type { Puzzle as PuzzleType } from '@/lib/puzzles';
import { notFound } from 'next/navigation';
import { useForm } from 'react-hook-form';
+import cookies from 'js-cookie';
import Button from './Button';
import Input from './Input';
@@ -10,6 +11,7 @@ import ToHTML from './ToHTML';
type PuzzleData = {
answer: string;
+ filename: string;
code_file: File[];
};
@@ -26,6 +28,7 @@ export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
} = useForm({
defaultValues: {
answer: '',
+ filename: '',
code_file: undefined
}
});
@@ -34,11 +37,15 @@ export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
const formData = new FormData();
formData.append('answer', data.answer);
+ formData.append('filename', data.code_file[0].name);
formData.append('code_file', data.code_file[0]);
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/puzzleResponse/${puzzle.id}`, {
method: 'POST',
- body: formData
+ body: formData,
+ headers: {
+ Authorization: `Bearer ${cookies.get('token')}}`
+ }
});
if (res.ok) {
diff --git a/ui/Puzzles.tsx b/ui/Puzzles.tsx
index 08ae810..42982a2 100644
--- a/ui/Puzzles.tsx
+++ b/ui/Puzzles.tsx
@@ -1,38 +1,68 @@
'use client';
-import { Chapter, Puzzle } from '@/lib/puzzles';
+import { usePuzzles } from '@/lib/hooks/use-puzzles';
import AppLink from './AppLink';
import Icon from './Icon';
-export default function Puzzles({ data }: { data: { chapters: Chapter[]; puzzles: Puzzle[] } }) {
- // const { data, isLoading } = usePuzzles();
+export default function Puzzles() {
+ const { data, isLoading } = usePuzzles();
return (
<>
- {data?.chapters?.map((chapter) => (
-
-
-
- Chapitre {chapter.id} - {chapter.name}
-
-
-
+ {(!isLoading &&
+ data?.chapters?.map((chapter) => (
+
+
+
+ Chapitre {chapter.id} - {chapter.name}
+
+
+
+ {data?.puzzles.map((puzzle) => (
+
+ -
+ {puzzle.name}
+
+
+
+ ))}
+
-
- {data?.puzzles.map((puzzle) => (
-
- -
- {puzzle.name}
-
+ {[...Array(3).keys()].map((i) => (
+
+
+
+
+
+
+ {[...Array(7).keys()].map((j) => (
+
-
-
- ))}
-
+ ))}
+
+
+ ))}
- ))}
+ )}
>
);
}