-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5555f64
commit 89363f1
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"use client"; | ||
import Scoreboard from "@/components/Scoreboard"; | ||
|
||
export default function ScoreboardPage() { | ||
return ( | ||
<> | ||
<Scoreboard ctfd_url="http://signage-api.sigpwny.com/" /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"use client"; | ||
import { useEffect, useState } from "react"; | ||
|
||
interface CTFdScoreboardUser { | ||
account_id: number; | ||
name: string; | ||
pos: number; | ||
} | ||
|
||
export default function Scoreboard({ ctfd_url }: { ctfd_url: string }) { | ||
const [scoreboard, setScoreboard] = useState<CTFdScoreboardUser[]>([]); | ||
function updateScoreboard(scoreboard_data: CTFdScoreboardUser[]) { | ||
// Sort by position | ||
scoreboard_data.sort((a, b) => a.pos - b.pos); | ||
// Update scoreboard | ||
setScoreboard(scoreboard_data); | ||
} | ||
// Initialize scoreboard from the CTFd API | ||
useEffect(() => { | ||
async function fetchScoreboard() { | ||
const endpoint = new URL("api/v1/scoreboard", ctfd_url); | ||
const response = await fetch(endpoint, { redirect: "follow", cache: "reload" }); | ||
if (!response.ok) return; | ||
const data = await response.json(); | ||
updateScoreboard(data.data as CTFdScoreboardUser[]); | ||
console.log(data.data); | ||
} | ||
fetchScoreboard(); | ||
}, []); | ||
return ( | ||
<div className="flex flex-col"> | ||
{scoreboard.map((user, idx) => ( | ||
<div key={idx} className="flex flex-row"> | ||
<span className="flex flex-col w-[5ch] font-medium font-mono text-[3rem] leading-none"> | ||
{user.pos} | ||
</span> | ||
<span className="flex flex-col font-medium font-mono text-[3rem] leading-none"> | ||
{user.name} | ||
</span> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} |