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
11 changes: 10 additions & 1 deletion frontend/src/pages/leaderboard/components/CodeDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { Box, Button, Dialog, DialogContent, DialogTitle } from "@mui/material";
import { Box, Button, Dialog, DialogContent, DialogTitle, Typography } from "@mui/material";
import { useState } from "react";
import { Link } from "react-router-dom";
import CodeBlock from "../../../components/codeblock/CodeBlock";

export function CodeDialog({
code,
fileName = "file",
isActive = false,
}: {
code: any;
fileName?: string;
isActive?: boolean;
}) {
const [open, setOpen] = useState(false);

if (isActive)
return (
<Typography variant="body2" sx={{ fontSize: "0.8125rem" }}>
{fileName}
</Typography>
);

if (!code)
return (
<Button
Expand Down
20 changes: 11 additions & 9 deletions frontend/src/pages/leaderboard/components/RankingLists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default function RankingsList({
}, [rankings]);

useEffect(() => {
if (!showLoc) return;
if (!submissionIds || submissionIds.length === 0 || !leaderboardId) return;
fetchCodes(leaderboardId, submissionIds)
.then((data) => {
Expand All @@ -118,7 +119,7 @@ export default function RankingsList({
// soft error handle it since it's not critical
console.warn("[RankingsList] Failed to fetch codes:", err);
});
}, [leaderboardId, submissionIds]);
}, [leaderboardId, submissionIds, showLoc]);

const toggleExpanded = (field: string) => {
setExpanded((prev) => ({
Expand Down Expand Up @@ -184,14 +185,6 @@ export default function RankingsList({
`+${formatMicroseconds(item.prev_score)}`}
</Typography>
</Grid>
<Grid size={3}>
<Typography>
<CodeDialog
code={codes.get(item?.submission_id)}
fileName={item.file_name}
/>
</Typography>
</Grid>
{showLoc && (
<Grid size={2}>
<Typography sx={styles.loc}>
Expand All @@ -204,6 +197,15 @@ export default function RankingsList({
</Typography>
</Grid>
)}
<Grid size={3}>
<Typography>
<CodeDialog
code={codes.get(item?.submission_id)}
fileName={item.file_name}
isActive={!showLoc}
/>
</Typography>
</Grid>
</Grid>
))}
</Stack>
Expand Down
Loading