diff --git a/src/api/problem.ts b/src/api/problem.ts index b9c99914f..a1c042d3e 100644 --- a/src/api/problem.ts +++ b/src/api/problem.ts @@ -34,4 +34,37 @@ export namespace ProblemService { } return res.data; } + + export async function putProblemPackage( + problemSlug: string, + packageFile: File, + ) { + let formData = new FormData(); + formData.append("file", packageFile); + let res = await client.put( + `/api/v1/problem/${problemSlug}/package`, + formData, + ); + if (res.status !== 200) { + throw Error("failed to put problem package"); + } + return res.data; + } + + export async function checkProblemSlug( + slug: string, + ): Promise<{ valid: boolean }> { + let res = await client.get<{ valid: boolean }>( + `/api/v1/problem/${slug}/check`, + ); + + return res.data; + } + + export async function deleteProblem(slug: string) { + let res = await client.delete(`/api/v1/problem/${slug}`); + if (res.status !== 200) { + throw Error("failed to delete problem"); + } + } } diff --git a/src/components/ProblemTable.tsx b/src/components/ProblemTable.tsx index 7d047641a..22f7deb97 100644 --- a/src/components/ProblemTable.tsx +++ b/src/components/ProblemTable.tsx @@ -2,6 +2,7 @@ import { TrashIcon, PencilSquareIcon } from "@heroicons/react/24/outline"; import { ProblemServiceModel } from "../typings/problem"; import React from "react"; import { useNavigate } from "react-router-dom"; +import { ProblemService } from "@/api/problem"; const columns = [ { name: "SLUG", uid: "slug" }, @@ -19,6 +20,8 @@ export interface ProblemTableProps { } const ProblemTable: React.FC = (props) => { + const [deletingSlug, setDeletingSlug] = React.useState(""); + const navigate = useNavigate(); return ( @@ -56,7 +59,9 @@ const ProblemTable: React.FC = (props) => { {props.showActions && ( - + setDeletingSlug(problemInfo.slug)} + /> )} @@ -75,7 +80,13 @@ const ProblemTable: React.FC = (props) => {