Skip to content
Open
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
33 changes: 10 additions & 23 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions frontend/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ export async function fetchCodes(
return r.data;
}

export async function onDeleteSubmission(
submissionId?: string | number,
): Promise<void> {
if (!submissionId) {
throw new Error("No submission ID provided for deletion");
}

const res = await fetch(`/api/submission/${submissionId}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
});
if (!res.ok) {
const text = await res.text();
throw new Error(`Failed to delete submission: ${text}`);
}
}

export async function fetchAllNews(): Promise<any> {
const res = await fetch("/api/news");
if (!res.ok) {
Expand Down
91 changes: 89 additions & 2 deletions frontend/src/pages/leaderboard/components/CodeDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
import { Box, Button, Dialog, DialogContent, DialogTitle } from "@mui/material";
import {
Box,
Button,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
Divider,
Stack,
Typography,
} from "@mui/material";
import { useState } from "react";
import CodeBlock from "../../../components/codeblock/CodeBlock";
import { onDeleteSubmission } from "../../../api/api";

export function CodeDialog({
code,
submissionId = undefined,
fileName = "file",
title = "Submission",
}: {
code: any;
title?: string;
submissionId?: number;
fileName?: string;
}) {
const [open, setOpen] = useState(false);

const [confirmDeleteOpen, setConfirmDeleteOpen] = useState(false);

const handleConfirmDelete = () => {
onDeleteSubmission(submissionId);
setConfirmDeleteOpen(false);
};

if (!code) return <Box>{fileName}</Box>;

return (
Expand All @@ -29,13 +51,78 @@ export function CodeDialog({
maxWidth="md"
fullWidth
>
<DialogTitle>Report JSON</DialogTitle>
<DialogTitle>{title}</DialogTitle>
<DialogContent dividers>
<Box>
<Typography variant="h6">
Information
</Typography>
<Stack direction="row" spacing={2}>
<Box>
<Typography variant="body2" color="text.secondary">
File Name
</Typography>
<Typography variant="body1" fontWeight={200}>
{fileName}
</Typography>
</Box>
<Box>
<Typography variant="body2" color="text.secondary">
Submission ID
</Typography>
<Typography variant="body1" fontWeight={200}>
{submissionId}
</Typography>
</Box>
</Stack>
<Box marginBottom={1}>
<Typography variant="h6">
Admin Operations
</Typography>
<Stack direction="row" spacing={2}>
<Box> Delete submission:</Box>
<Button
color="error"
size="small"
variant="outlined"
onClick={() => setConfirmDeleteOpen(true)}
>
delete
</Button>
</Stack>
</Box>
</Box>
<Box>
<CodeBlock code={code} />
</Box>
</DialogContent>
</Dialog>

{/* Confirm delete dialog */}
<Dialog
open={confirmDeleteOpen}
onClose={() => setConfirmDeleteOpen(false)}
>
<DialogTitle>Delete submission?</DialogTitle>
<DialogContent>
<Typography variant="body2">
Are you sure to delete submission {submissionId}, file {fileName}?
This action cannot be undone. The submission and all related data
will be permanently removed.
</Typography>
</DialogContent>
<DialogActions>
<Button onClick={() => setConfirmDeleteOpen(false)}>Cancel</Button>

<Button
color="error"
variant="contained"
onClick={handleConfirmDelete}
>
Delete
</Button>
</DialogActions>
</Dialog>
</>
);
}
1 change: 1 addition & 0 deletions frontend/src/pages/leaderboard/components/RankingLists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export default function RankingsList({
<CodeDialog
code={codes.get(item?.submission_id)}
fileName={item.file_name}
submissionId={item?.submission_id}
/>
</Typography>
</Grid>
Expand Down
1 change: 0 additions & 1 deletion kernelboard/api/leaderboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from kernelboard.lib.status_code import http_error, http_success
from http import HTTPStatus


leaderboard_bp = Blueprint("leaderboard_bp", __name__, url_prefix="/leaderboard")


Expand Down
Loading