diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx
index 9819d9e..28e2b3e 100644
--- a/app/dashboard/page.tsx
+++ b/app/dashboard/page.tsx
@@ -19,7 +19,7 @@ export default function Page() {
isLoading={isLoading}
icon="pie-chart-line"
title="Puzzles résolus"
- data={me?.completions}
+ data={me?.completions || 0}
/>
-
+
diff --git a/ui/Puzzle.tsx b/ui/Puzzle.tsx
index 73eb556..e65e9d2 100644
--- a/ui/Puzzle.tsx
+++ b/ui/Puzzle.tsx
@@ -15,11 +15,17 @@ type PuzzleData = {
code_file: File[];
};
+type Granted = {
+ [key: string]: number;
+};
+
export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
if (!puzzle) {
notFound();
}
+ // const [granted, setGranted] = useState({});
+
const {
register,
handleSubmit,
@@ -81,6 +87,7 @@ export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
required
{...register('answer')}
/>
+
{/* {
const intervalId = setInterval(() => {
const timeDifference = targetDate.getTime() - Date.now();
diff --git a/ui/UserAuthForm.tsx b/ui/UserAuthForm.tsx
index 0144d7c..7516579 100644
--- a/ui/UserAuthForm.tsx
+++ b/ui/UserAuthForm.tsx
@@ -53,43 +53,53 @@ export default function UserAuthForm() {
}
);
- if (!res || res.status !== 200) {
+ if (!res) {
setError('passwd', {
type: 'manual',
message: "Une erreur s'est produite."
});
+
+ setIsLoading(false);
}
- if (res && !isSignIn) {
- const { username_valid, email_valid } = await res.json();
- if (!username_valid) {
- setError('pseudo', {
- type: 'manual',
- message: "Nom d'utilisateur indisponible"
- });
- }
- if (!email_valid) {
- setError('email', {
- type: 'manual',
- message: 'Adresse e-mail indisponible'
- });
+ if (!isSignIn) {
+ if (res.status === 400) {
+ const { username_valid, email_valid } = await res.json();
+ if (!username_valid) {
+ setError('pseudo', {
+ type: 'manual',
+ message: "Nom d'utilisateur indisponible"
+ });
+
+ setIsLoading(false);
+ }
+ if (!email_valid) {
+ setError('email', {
+ type: 'manual',
+ message: 'Adresse e-mail indisponible'
+ });
+ }
+ setIsLoading(false);
}
}
- if (res && res.ok && res.status === 200) {
+ if (res.status === 200) {
const token = res.headers.get('Authorization')?.split(' ')[1];
if (token) {
+ console.log(token);
+
cookies.set('token', token, {
sameSite: 'strict',
secure: process.env.NODE_ENV === 'production'
});
router.refresh();
}
- } else if (res && res.status === 400) {
+ } else {
setError('passwd', {
type: 'manual',
message: "Nom d'utilisateur ou mot de passe incorrect"
});
+ setIsLoading(false);
}
setIsLoading(false);
diff --git a/ui/events/Leaderboard.tsx b/ui/events/Leaderboard.tsx
index 0ba42d6..42254b4 100644
--- a/ui/events/Leaderboard.tsx
+++ b/ui/events/Leaderboard.tsx
@@ -6,15 +6,16 @@ import type { ScoreEvent } from '@/lib/leaderboard';
import type { SWRSubscription } from 'swr/subscription';
import useSWRSubscription from 'swr/subscription';
import Podium from './podium/Podium';
+import { Timer } from '../Timer';
const SCORE_COLORS = ['text-yellow-400', 'text-gray-400', 'text-orange-400'];
-export default function EventLeaderboard({ token, id }: { token: string; id: number }) {
+export default function EventLeaderboard({ id }: { token: string; id: number }) {
const subscription: SWRSubscription = (key, { next }) => {
const socket = new WebSocket(key);
socket.addEventListener('message', (event) => {
- next(JSON.parse(event.data));
+ next(null, JSON.parse(event.data));
});
socket.addEventListener('error', (event) => {
@@ -25,12 +26,10 @@ export default function EventLeaderboard({ token, id }: { token: string; id: num
};
const { data, error } = useSWRSubscription(
- `ws://${process.env.NEXT_PUBLIC_API_URL?.split('//')[1]}/rleaderboard/${id}`,
+ `wss://${process.env.NEXT_PUBLIC_API_URL?.split('//')[1]}/rleaderboard/${id}`,
subscription
);
- // const { data, isLoading } = useLeaderboardEvent({ token, id });
-
const scores = [data?.groups]
.flat()
.sort((a, b) => a!.rank - b!.rank)
@@ -39,13 +38,10 @@ export default function EventLeaderboard({ token, id }: { token: string; id: num
place
}));
- if (error) return failed to load
;
- if (!data) return loading...
;
-
return (
{data && }
- {/* */}
+ {data && data.end_date && }
{data?.groups.map((group, key) => (