From aedf2bbf17a92bbb12442b0cbe15a041dabc167f Mon Sep 17 00:00:00 2001 From: Paul Pan Date: Sun, 16 Jul 2023 20:50:34 +0800 Subject: [PATCH] feat: problem detail page --- package.json | 1 + pnpm-lock.yaml | 3 + src/pages/problem.tsx | 152 ++++++++++++++++++++++++++++-------------- 3 files changed, 107 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index 05c8bac..8f5cf38 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "preview": "vite preview" }, "dependencies": { + "@ant-design/icons": "^5.1.4", "@sentry/react": "^7.58.1", "@sentry/vite-plugin": "^2.4.0", "antd": "^5.7.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2d6da55..9bce1a5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,9 @@ settings: excludeLinksFromLockfile: false dependencies: + '@ant-design/icons': + specifier: ^5.1.4 + version: 5.1.4(react-dom@18.2.0)(react@18.2.0) '@sentry/react': specifier: ^7.58.1 version: 7.58.1(react@18.2.0) diff --git a/src/pages/problem.tsx b/src/pages/problem.tsx index ae7968c..824c96b 100644 --- a/src/pages/problem.tsx +++ b/src/pages/problem.tsx @@ -1,61 +1,115 @@ -import { Row, Col, Card, Button, Space } from "antd"; +import { + Row, + Col, + Collapse, + CollapseProps, + Descriptions, + Tag, + Space, + Typography, + Button, +} from "antd"; +import { PlayCircleOutlined, SearchOutlined } from "@ant-design/icons"; +import { Link, useLoaderData, useNavigate } from "react-router-dom"; + import Markdown from "../components/markdown.tsx"; -import { useLoaderData } from "react-router-dom"; +import { DetailsResp, ProblemApi } from "../api/problem.ts"; -interface LoaderProps { - params: { - id: string; - }; -} - -interface ProblemProps { - text: string; -} - -export async function ProblemLoader({ params }: LoaderProps) { - console.log(params.id); - const text = ` -# Problem 1 - -| Time Limit | Memory Limit | -| ---------- | ------------ | -| 1s | 256MB | - -\`\`\`cpp -#include -using namespace std; -int main() { - cout << "hello world" << endl; - return 0; -} -\`\`\` - -I'm a paragraph. - -inline \`code\` test - -`; - - return { text: text }; +export async function ProblemLoader({ params }: { params: { id: string } }) { + const id = parseInt(params.id); + if (isNaN(id)) { + throw new Error("invalid problem id"); + } + return await ProblemApi.Details({ pid: id }); } function ProblemPage() { - const { text } = useLoaderData() as ProblemProps; + const details = useLoaderData() as DetailsResp; + const navigate = useNavigate(); + + const problemInfo = ( + + + + + {details.problem.provider.nick_name} + + + + + + {details.context.Languages.map((l) => ( + {l.Lang} + ))} + + + + {details.context.Tasks.length} + + + ); + const runtimeLimit = ( + + + {details.context.Runtime.TimeLimit} ms + + + {details.context.Runtime.MemoryLimit} MB + + + {details.context.Runtime.NProcLimit} + + + ); + const actionBtn = ( + + + + + ); + + const miscItems: CollapseProps["items"] = [ + { + key: "1", + label: "Problem Info", + children: problemInfo, + }, + { + key: "2", + label: "Runtime Limit", + children: runtimeLimit, + }, + { + key: "3", + label: "Action", + children: actionBtn, + }, + ]; + + const ProblemStatement = ; + const MiscPanel = ( + + ); return ( <> - - - - - - - - - - - + {ProblemStatement} + {MiscPanel} );