Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/pages/leaderboard/Leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default function Leaderboard() {
<TabPanel value={tab} index={0}>
<Box>
{Object.entries(data.rankings).length > 0 ? (
<RankingsList rankings={data.rankings} leaderboardId={id} />
<RankingsList rankings={data.rankings} leaderboardId={id} deadline={data.deadline} />
) : (
<Box display="flex" flexDirection="column" alignItems="center">
<Typography variant="h6" fontWeight="bold">
Expand Down
31 changes: 19 additions & 12 deletions frontend/src/pages/leaderboard/components/RankingLists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { formatMicroseconds } from "../../../lib/utils/ranking.ts";
import { getMedalIcon } from "../../../components/common/medal.tsx";
import { fetchCodes } from "../../../api/api.ts";
import { CodeDialog } from "./CodeDialog.tsx";
import { isExpired } from "../../../lib/date/utils.ts";

interface RankingItem {
file_name: string;
Expand All @@ -27,6 +28,7 @@ interface RankingItem {
interface RankingsListProps {
rankings: Record<string, RankingItem[]>;
leaderboardId?: string;
deadline?: string;
}

const styles: Record<string, SxProps<Theme>> = {
Expand Down Expand Up @@ -70,13 +72,16 @@ const styles: Record<string, SxProps<Theme>> = {
loc: {
fontFamily: "monospace",
color: "text.secondary",
textAlign: "right",
},
};

export default function RankingsList({
rankings,
leaderboardId,
deadline,
}: RankingsListProps) {
const showLoc = !!deadline && isExpired(deadline);
const [expanded, setExpanded] = useState<Record<string, boolean>>({});
const [colorHash, _] = useState<string>(
Math.random().toString(36).slice(2, 8),
Expand Down Expand Up @@ -168,12 +173,12 @@ export default function RankingsList({
{item.user_name} {getMedalIcon(item.rank)}
</Typography>
</Grid>
<Grid size={2}>
<Grid size={showLoc ? 2 : 3}>
<Typography sx={styles.score}>
{formatMicroseconds(item.score)}
</Typography>
</Grid>
<Grid size={2}>
<Grid size={showLoc ? 2 : 3}>
<Typography sx={styles.delta}>
{item.prev_score > 0 &&
`+${formatMicroseconds(item.prev_score)}`}
Expand All @@ -187,16 +192,18 @@ export default function RankingsList({
/>
</Typography>
</Grid>
<Grid size={2}>
<Typography sx={styles.loc}>
{(() => {
const code = codes.get(item?.submission_id);
if (!code) return "";
const lines = code.split("\n").length;
return `${lines} LOC`;
})()}
</Typography>
</Grid>
{showLoc && (
<Grid size={2}>
<Typography sx={styles.loc}>
{(() => {
const code = codes.get(item?.submission_id);
if (!code) return "";
const lines = code.split("\n").length;
return `${lines} LOC`;
})()}
</Typography>
</Grid>
)}
</Grid>
))}
</Stack>
Expand Down
Loading