-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
2 changed files
with
74 additions
and
1 deletion.
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
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,71 @@ | ||
import { useContext, useEffect, useState } from "react"; | ||
import { EpisodeContext } from "../contexts/EpisodeContext"; | ||
import { Api } from "../utils/api"; | ||
import BattlecodeTable from "../components/BattlecodeTable"; | ||
import { PaginatedTeamPublicList } from "../utils/types/model/PaginatedTeamPublicList"; | ||
import BattlecodeTableBottomElement from "../components/BattlecodeTableBottomElement"; | ||
|
||
const Rankings: React.FC = () => { | ||
const episodeId = useContext(EpisodeContext); | ||
|
||
const [page, setPage] = useState<number>(1); | ||
const [searchQuery, setSearchQuery] = useState<string>(""); | ||
const [requireActiveSubmission, setRequireActiveSubmission] = | ||
Check warning on line 13 in frontend2/src/views/Rankings.tsx GitHub Actions / Frontend linting / unit tests
|
||
useState<boolean>(false); | ||
|
||
const [data, setData] = useState<PaginatedTeamPublicList | undefined>( | ||
undefined | ||
); | ||
|
||
const queryVars = { | ||
episodeId: episodeId.episodeId, | ||
searchQuery: searchQuery, | ||
requireActiveSubmission: false, | ||
page: page, | ||
}; | ||
|
||
useEffect(() => { | ||
Api.searchTeams( | ||
queryVars.episodeId, | ||
queryVars.searchQuery, | ||
queryVars.requireActiveSubmission, | ||
queryVars.page | ||
).then((res) => setData(res)); | ||
}, [queryVars]); | ||
|
||
if (!data) { | ||
return <>Loading...</>; | ||
} | ||
|
||
return ( | ||
<> | ||
<h1 className="mb-4 text-4xl font-extrabold leading-none tracking-tight text-gray-900 md:text-5xl lg:text-6xl dark:text-white"> | ||
Rankings | ||
</h1> | ||
<div style={{ height: 100 }} /> | ||
<BattlecodeTable | ||
data={data.results ?? []} | ||
bottomElement={ | ||
<BattlecodeTableBottomElement | ||
totalCount={data.count ?? 0} | ||
pageSize={10} | ||
currentPage={page} | ||
onPage={(page) => setPage(page)} | ||
/> | ||
} | ||
columns={[ | ||
{ | ||
header: "Rating", | ||
value: (team) => team.profile?.rating ?? 0, | ||
}, | ||
{ | ||
header: "Team", | ||
value: (team) => team.name, | ||
}, | ||
]} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default Rankings; |