diff --git a/src/components/SourceEditor.tsx b/src/components/SourceEditor.tsx index d218e45..54e9ae3 100644 --- a/src/components/SourceEditor.tsx +++ b/src/components/SourceEditor.tsx @@ -2,13 +2,14 @@ import "katex/dist/katex.min.css"; import React, { useState } from "react"; import Editor from "@monaco-editor/react"; import { editor } from "monaco-editor"; +import { Box } from "@mui/material"; interface Props { value: string; language?: string; onChange?: (value: string) => void; readOnly: boolean; - autoHeight: boolean; + height?: number; } const editorMode = (lang?: string) => { @@ -48,45 +49,48 @@ const editorMode = (lang?: string) => { return "plaintext"; }; +const MIN_EDITOR_HEIGHT = 100; + const SourceEditor: React.FC = (props) => { - const minHeight = 100; - const { value, language, onChange, readOnly, autoHeight } = props; - const [editorHeight, setEditorHeight] = useState(minHeight); + const { value, language, onChange, readOnly, height } = props; + const [editorHeight, setEditorHeight] = useState(height ?? MIN_EDITOR_HEIGHT); const mode = editorMode(language); const updateHeight = (editor: editor.IStandaloneCodeEditor) => { - if (autoHeight) { - setEditorHeight(Math.max(minHeight, editor.getContentHeight())); + if (height === undefined) { + setEditorHeight(Math.max(MIN_EDITOR_HEIGHT, editor.getContentHeight())); } }; return ( - { - if (src !== undefined && onChange) onChange(src); - }} - onMount={(editor) => { - editor.onDidContentSizeChange(() => { + + { + if (src !== undefined && onChange) onChange(src); + }} + onMount={(editor) => { + editor.onDidContentSizeChange(() => { + updateHeight(editor); + }); updateHeight(editor); - }); - updateHeight(editor); - }} - options={{ - readOnly: readOnly, - scrollBeyondLastColumn: 0, - scrollBeyondLastLine: false, - minimap: { - enabled: false, - }, - scrollbar: { - alwaysConsumeMouseWheel: false, - }, - }} - /> + }} + options={{ + readOnly: readOnly, + scrollBeyondLastColumn: 0, + scrollBeyondLastLine: false, + minimap: { + enabled: false, + }, + scrollbar: { + alwaysConsumeMouseWheel: false, + }, + }} + /> + ); }; diff --git a/src/pages/Hack.tsx b/src/pages/Hack.tsx index d0bf97e..fd44f82 100644 --- a/src/pages/Hack.tsx +++ b/src/pages/Hack.tsx @@ -4,7 +4,14 @@ import React, { useState } from "react"; import { useNavigate } from "react-router-dom"; import SourceEditor from "../components/SourceEditor"; import { useHackMutation } from "../api/client_wrapper"; -import { Container, FormControl, TextField } from "@mui/material"; +import { + Box, + Container, + FormControl, + Tab, + Tabs, + TextField, +} from "@mui/material"; import { refactorTestCase } from "../utils/hack"; const Hack: React.FC = () => { @@ -16,6 +23,7 @@ const Hack: React.FC = () => { }); const [submissionId, setSubmissionId] = useState(""); const [testCase, setTestCase] = useState(""); + const [tabIndex, setTabIndex] = useState(0); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); @@ -27,11 +35,11 @@ const Hack: React.FC = () => { return ( - + Hack -
+ { onChange={(e) => setSubmissionId(e.target.value)} /> - - { - setTestCase(e); - }} - readOnly={false} - autoHeight={false} - /> - + + setTabIndex(newValue)} + > + + + + + + {tabIndex === 0 && ( + + + { + setTestCase(e); + }} + readOnly={false} + height={600} + /> + + + )} + {tabIndex === 1 && ( + + + TODO + + + )} - +
); }; diff --git a/src/pages/HackInfo.tsx b/src/pages/HackInfo.tsx index cb50839..d06865e 100644 --- a/src/pages/HackInfo.tsx +++ b/src/pages/HackInfo.tsx @@ -21,6 +21,9 @@ const HackInfo: React.FC = () => { if (hackInfoQuery.isLoading) { return ( + + Hack #{ID} + ); @@ -29,6 +32,9 @@ const HackInfo: React.FC = () => { if (hackInfoQuery.isError) { return ( + + Hack #{ID} + {(hackInfoQuery.error as RpcError).toString()} diff --git a/src/pages/HackList.tsx b/src/pages/HackList.tsx new file mode 100644 index 0000000..cb50839 --- /dev/null +++ b/src/pages/HackList.tsx @@ -0,0 +1,69 @@ +import Box from "@mui/material/Box"; +import Typography from "@mui/material/Typography"; +import React from "react"; +import { useParams } from "react-router-dom"; +import { useHackInfo } from "../api/client_wrapper"; +import CircularProgress from "@mui/material/CircularProgress"; +import Link from "@mui/material/Link"; +import { Alert, Container } from "@mui/material"; +import { HackInfoResponse } from "../proto/library_checker"; +import { RpcError } from "@protobuf-ts/runtime-rpc"; + +const HackInfo: React.FC = () => { + const { ID } = useParams<"ID">(); + if (!ID) { + throw new Error(`hack ID is not defined`); + } + const hackInfoQuery = useHackInfo(parseInt(ID), { + refetchInterval: 1000, + }); + + if (hackInfoQuery.isLoading) { + return ( + + + + ); + } + + if (hackInfoQuery.isError) { + return ( + + + {(hackInfoQuery.error as RpcError).toString()} + + + ); + } + return ( + + + Hack #{ID} + + + + ); +}; + +export default HackInfo; + +const HackInfoBody: React.FC<{ + info: HackInfoResponse; +}> = (props) => { + const { info } = props; + return ( + + + Submission:{" "} + + #{info.overview?.submissionId} + + + Status: {info.overview?.status} + TestCase +
{new TextDecoder().decode(info.testCase)}
+ Checker output +
{new TextDecoder().decode(info.checkerOut)}
+
+ ); +}; diff --git a/src/pages/ProblemInfo.tsx b/src/pages/ProblemInfo.tsx index f3f97fd..ea00e77 100644 --- a/src/pages/ProblemInfo.tsx +++ b/src/pages/ProblemInfo.tsx @@ -251,7 +251,6 @@ const SolveHpp: React.FC<{ value={solveHppQuery.data} language="cpp" readOnly={true} - autoHeight={true} /> )} @@ -317,12 +316,7 @@ const SubmitForm: React.FC<{ problemId: string }> = (props) => {
- + = (props) => { setSource(e); }} readOnly={false} - autoHeight={false} + height={400} /> diff --git a/src/pages/StatementViewer.tsx b/src/pages/StatementViewer.tsx index eed6b9b..b48a4ec 100644 --- a/src/pages/StatementViewer.tsx +++ b/src/pages/StatementViewer.tsx @@ -304,18 +304,13 @@ const EditorSide: React.FC<{ task.md - + @@ -325,18 +320,13 @@ const EditorSide: React.FC<{ info.toml - + diff --git a/src/pages/SubmissionInfo.tsx b/src/pages/SubmissionInfo.tsx index 279a4a0..034b4b0 100644 --- a/src/pages/SubmissionInfo.tsx +++ b/src/pages/SubmissionInfo.tsx @@ -117,12 +117,7 @@ const SubmissionInfoBody: React.FC<{ }} /> - + );