diff --git a/src/apis/judge.ts b/src/apis/judge.ts index 263865645..f64a8e468 100644 --- a/src/apis/judge.ts +++ b/src/apis/judge.ts @@ -8,7 +8,7 @@ export async function postJudge(slug: string, code: string, language: string) { }; let data = JSON.stringify(body); - let res = await axiosClient.post( + let res = await axiosClient.post( `/api/v1/problem/${slug}/judge`, data, ); diff --git a/src/components/display/MarkdownRender.tsx b/src/components/display/MarkdownRender.tsx index 7ac9a8023..f3fbfb7ec 100644 --- a/src/components/display/MarkdownRender.tsx +++ b/src/components/display/MarkdownRender.tsx @@ -7,6 +7,7 @@ import { vscDarkPlus } from "react-syntax-highlighter/dist/esm/styles/prism"; import rehypeReact from "rehype-react"; import { joinClasses } from "@/utils/common"; import rehypeRaw from "rehype-raw"; +import { useTranslation } from "react-i18next"; interface MarkdownRenderProps { content: string; @@ -53,6 +54,8 @@ interface CodeBlockProps { } const CodeBlock: React.FC = (props) => { + const { t } = useTranslation(); + const handleCopy = () => { copy(props.value); }; @@ -63,7 +66,7 @@ const CodeBlock: React.FC = (props) => { onClick={handleCopy} className="btn btn-xs absolute right-0 top-[-1.25px] rounded" > - Copy + {t("Copy")} {props.language === "text" ? ( {props.value} diff --git a/src/hooks/judge.ts b/src/hooks/judge.ts index b09caceab..6d05a3e6b 100644 --- a/src/hooks/judge.ts +++ b/src/hooks/judge.ts @@ -24,30 +24,24 @@ export const useJudge = (uid: string) => { export const useRunJudge = (slug: string) => { const [src, setSrc] = useState(""); const [src_language, setSrcLanguage] = useState(""); - const [verdicts, setVerdicts] = useState( - [], - ); - function runJudge(postJudge: () => void) { + function runJudge( + afterJudgePosted: (judgeInfo: JudgeServiceModel.JudgeInfo) => void, + ) { JudgeService.postJudge(slug, src, src_language) .then((res) => { - setVerdicts(res); - postJudge(); + afterJudgePosted(res); }) .catch((err) => { console.log(err); }); } - function getVerdicts() { - return verdicts; - } - function getSrcLanguage() { return src_language; } - return { runJudge, getVerdicts, setSrc, setSrcLanguage, getSrcLanguage }; + return { runJudge, setSrc, setSrcLanguage, getSrcLanguage }; }; export const useJudgeList = () => { diff --git a/src/i18n/resources/zh_CN.ts b/src/i18n/resources/zh_CN.ts index 51b6d8767..f85e8082d 100644 --- a/src/i18n/resources/zh_CN.ts +++ b/src/i18n/resources/zh_CN.ts @@ -18,6 +18,9 @@ const ZH_CN_TRANSLATIONS: Resource = { Search: "搜索", Login: "登录", Logout: "登出", + Submit: "提交", + Copy: "复制", + "or Register": "或注册", "Welcome!": "欢迎!", "input title": "输入标题", @@ -26,7 +29,10 @@ const ZH_CN_TRANSLATIONS: Resource = { "Submit Time": "提交时间", "Accept Count": "通过数", "Accept Rate": "通过率", + "Your solution": "你的解答", "Just look at yourself": "只看自己", + "Click and confirm submission": "点击并确认提交", + "Please login first": "请先登录", Theme: "主题", diff --git a/src/layouts/Layout.tsx b/src/layouts/Layout.tsx index 9d0559d5e..aa429bbd8 100644 --- a/src/layouts/Layout.tsx +++ b/src/layouts/Layout.tsx @@ -5,10 +5,7 @@ import PageBreadcrumbs from "@/components/navigation/PageBreadcrumbs"; import { useEffect } from "react"; import { getCurrentUserAction } from "@/store/sagas/user"; import { useDispatch, useSelector } from "react-redux"; -import { - AddMessageSagaPattern, - RemoveMessageSagaPattern, -} from "@/store/sagas/message"; +import { RemoveMessageSagaPattern } from "@/store/sagas/message"; import { messageMapSelector } from "@/store/selectors"; import { joinClasses } from "@/utils/common"; import { useTranslation } from "react-i18next"; @@ -23,17 +20,6 @@ const Layout: React.FC = (props) => { let dispatch = useDispatch(); let messageMap = useSelector(messageMapSelector); - useEffect(() => { - dispatch({ - type: AddMessageSagaPattern, - payload: { - id: "welcome", - content: "🥰 Welcome to OJ Lab!", - duration: 3000, - }, - }); - }, [dispatch]); - useEffect(() => { dispatch(getCurrentUserAction); // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/src/pages/problem/Problem.tsx b/src/pages/problem/Problem.tsx index e2a8a659b..e894e1cb9 100644 --- a/src/pages/problem/Problem.tsx +++ b/src/pages/problem/Problem.tsx @@ -6,6 +6,11 @@ import MarkdownRender from "@/components/display/MarkdownRender"; import { useProblem } from "@/hooks/problem"; import { useRunJudge } from "@/hooks/judge"; import { isGhPages, isMock } from "@/utils/environment"; +import { useDispatch, useSelector } from "react-redux"; +import { AddMessageSagaPattern } from "@/store/sagas/message"; +import { userInfoSelector } from "@/store/selectors"; +import { joinClasses } from "@/utils/common"; +import { t } from "i18next"; const mockDefaultCode = `#include using namespace std; @@ -19,8 +24,9 @@ int main() { const Problem: React.FC = () => { const navigate = useNavigate(); + const dispatch = useDispatch(); + const userInfo = useSelector(userInfoSelector); const slug = useParams().slug as string; - const [toggleToast, setToggleToast] = React.useState(false); const codeEditorContainer = React.useRef(null); const { getProblem } = useProblem(slug, () => { @@ -35,22 +41,13 @@ const Problem: React.FC = () => { return (
- {toggleToast && ( -
-
- Judge sent successfully. -
-
- )} -

{getProblem()?.title}

- -

Your Solution

+

{t("Your solution")}