diff --git a/lib/leaderboard.ts b/lib/leaderboard.ts index d77991c..525957b 100644 --- a/lib/leaderboard.ts +++ b/lib/leaderboard.ts @@ -68,7 +68,7 @@ export type ScoreEvent = { { pseudo: string; tries: number; - completions: number; + completion: number; score: number; } ]; diff --git a/ui/Leaderboard.tsx b/ui/Leaderboard.tsx index eafe411..1c4c046 100644 --- a/ui/Leaderboard.tsx +++ b/ui/Leaderboard.tsx @@ -14,6 +14,8 @@ const SCORE_COLORS = ['text-yellow-400', 'text-gray-400', 'text-orange-400']; export default function Leaderboard({ token }: { token: string }) { // const { data, isLoading } = useLeaderboard({ token }); + const CHAPITRE_EVENT = 3; + const subscription: SWRSubscription = (key, { next }) => { const socket = new WebSocket(key); @@ -29,7 +31,7 @@ export default function Leaderboard({ token }: { token: string }) { }; const { data } = useSWRSubscription( - `wss://${process.env.NEXT_PUBLIC_API_URL?.split('//')[1]}/rleaderboard`, + `wss://${process.env.NEXT_PUBLIC_API_URL?.split('//')[1]}/rleaderboard${CHAPITRE_EVENT}`, subscription ); @@ -39,9 +41,11 @@ export default function Leaderboard({ token }: { token: string }) { const { data: groups } = useGroups({ token }); + console.log(groups); + if (groups) { options = groups - .filter((group) => !group.chapter) + .filter((group) => group.chapter === null) .map((group) => ({ value: group.name, title: group.name })) .filter((group, index, self) => self.findIndex((g) => g.value === group.value) === index) .sort((a, b) => a.title.localeCompare(b.title)); @@ -56,8 +60,6 @@ export default function Leaderboard({ token }: { token: string }) { return data; }, [data, filter]); - console.log(filteredData); - return (
@@ -82,40 +84,49 @@ export default function Leaderboard({ token }: { token: string }) { )} */}
- Waiting for the leaderboard to be implemented (Xavier WSS) - {/*
    - {(!isLoading && - filteredData((group, key) => ( -
  • -
    - - {score.rank} +
      + {data?.groups.map((group, key) => ( +
    • +
      + + {group.rank} + +
      +
      + {group.name} + + {group.players && group.players.length > 1 + ? group.players + .map((player) => player.pseudo || 'Anonyme') + .sort((a, b) => a.localeCompare(b)) + .join(', ') + : group.players[0].pseudo} + +
      +
      +
      +
      +
      + Essaies + + {group.players.reduce((a, b) => a + b.tries, 0)} -
      - -
      - {score.pseudo} - - {score.groups - ?.map((g) => g.name) - .sort((a, b) => a.localeCompare(b)) - .join(', ')} - -
      -
      -
      -
      - Puzzles - {score.completions} -
      -
      - Score - {score.score} -
      + {/*
      + Puzzles + + {group.players.reduce((a, b) => a + b.completion, 0)} + +
      */} +
      + Score + + {group.players.reduce((a, b) => a + b.score, 0)} +
      -
    • - ))) || +
    +
  • + )) || [...Array(20).keys()].map((i) => ( ))} -
*/} +
); diff --git a/ui/Puzzle.tsx b/ui/Puzzle.tsx index a34cf4a..045883a 100644 --- a/ui/Puzzle.tsx +++ b/ui/Puzzle.tsx @@ -116,11 +116,11 @@ export default function Puzzle({ token, id }: { token: string; id: number }) { ) : (
-

- Tentatives : {puzzle.tries} +

+ Tentatives : {puzzle.tries}

-

- Score : {puzzle.score} (Score maximum:{' '} +

+ Score : {puzzle.score} (Score maximum:{' '} {puzzle.scoreMax})

diff --git a/ui/ToHTML.tsx b/ui/ToHTML.tsx index d6cd91b..1b6ccd1 100644 --- a/ui/ToHTML.tsx +++ b/ui/ToHTML.tsx @@ -13,7 +13,7 @@ export default function ToHTML({ data, className }: { data: string; className?: a: ({ ...props }) => (