Skip to content

Commit

Permalink
Some perf & fixs
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Feb 9, 2024
1 parent 88934a2 commit a7760ad
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 37 deletions.
3 changes: 2 additions & 1 deletion src/hooks/judge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ export const useJudge = (slug: string) => {
[],
);

function runJudge() {
function runJudge(postSubmission: () => void) {
JudgeService.postSubmission(slug, src, src_language)
.then((res) => {
setVerdicts(res);
postSubmission();
})
.catch((err) => {
console.log(err);
Expand Down
6 changes: 3 additions & 3 deletions src/mocks/rest/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Hello! world!
\`\`\`
`,
tags: ["Primer"],
tags: [{ name: "Primer" }],
};

return HttpResponse.json(response);
Expand All @@ -53,12 +53,12 @@ export const getProblemInfoList = http.get("/api/v1/problem", (info) => {
{
slug: "hello-world",
title: "Hello World",
tags: ["Pimer"],
tags: [{ name: "Pimer" }],
},
{
slug: "a-plus-b-problem",
title: "A+B Problem",
tags: ["Primer", "Math"],
tags: [{ name: "Primer" }, { name: "Math" }],
},
],
};
Expand Down
76 changes: 47 additions & 29 deletions src/pages/Problem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { judgeVerdictListPipe } from "../pipes/judge";
import { useEffect } from "react";
import UserLayout from "../layouts/userLayout/UserLayout";
import { useNavigate, useParams } from "react-router-dom";
import React from "react";

const defaultCode = `#include <iostream>
using namespace std;
Expand All @@ -21,6 +22,7 @@ int main() {
const Problem: React.FC = () => {
const navigate = useNavigate();
const slug = useParams().slug as string;
const [toggleToast, setToggleToast] = React.useState<boolean>(false);

const { getProblem } = useProblem(slug, () => {
navigate("/problem");
Expand All @@ -32,38 +34,54 @@ const Problem: React.FC = () => {
}, [setSrcLanguage]);

return (
<UserLayout title={getProblem()?.title}>
<div className="flex flex-1 flex-col gap-6 sm:flex-row">
<div className="w-full flex-1">
<MarkdownRender
content={getProblem()?.description || ""}
rehypePlugin="rehypeKatex"
/>
<>
{toggleToast && (
<div className="toast toast-center toast-top z-10">
<div className="alert alert-success">
<span>Submission sent successfully.</span>
</div>
</div>
<div className="flex w-1/2 flex-col gap-4">
<CodeEditor
className="h-full min-h-96 w-full overflow-hidden rounded-lg"
value={defaultCode}
onChange={(value: string) => {
setSrc(value);
}}
/>
)}
<UserLayout title={getProblem()?.title}>
<div className="flex flex-1 flex-col gap-6 sm:flex-row">
<div className="w-full flex-1">
<MarkdownRender
content={getProblem()?.description || ""}
rehypePlugin="rehypeKatex"
/>
</div>
<div className="flex w-1/2 flex-col gap-4">
<CodeEditor
className="h-full min-h-96 w-full overflow-hidden rounded-lg"
value={defaultCode}
onChange={(value: string) => {
setSrc(value);
}}
/>
</div>
</div>
</div>
<div className="relative">
<button
className="btn btn-primary absolute bottom-4 right-4 self-end"
onClick={runJudge}
>
Submit
</button>
</div>
{getVerdicts().length > 0 && (
<div className="my-8">
<JudgeVerdictTable data={judgeVerdictListPipe(getVerdicts())} />
<div className="relative">
<button
className="btn btn-primary absolute bottom-4 right-4 self-end"
onClick={() => {
runJudge(() => {
setToggleToast(true);
setTimeout(() => {
setToggleToast(false);
}, 3000);
});
}}
>
Submit
</button>
</div>
)}
</UserLayout>
{getVerdicts().length > 0 && (
<div className="my-8">
<JudgeVerdictTable data={judgeVerdictListPipe(getVerdicts())} />
</div>
)}
</UserLayout>
</>
);
};

Expand Down
3 changes: 1 addition & 2 deletions src/pages/ProblemList.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import NewsCard from "../components/NewsCard";
import ProblemTable from "../components/ProblemTable";
import { useEvent } from "../hooks/event";
import { useProblemInfoList } from "../hooks/problem";
import UserLayout from "../layouts/userLayout/UserLayout";

const ProblemList: React.FC = () => {
const { getProblemInfoList } = useProblemInfoList();
useEvent();
// useEvent();

return (
<UserLayout>
Expand Down
3 changes: 1 addition & 2 deletions src/pages/SubmissionList.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import NewsCard from "../components/NewsCard";
import SubmissionTable from "../components/SubmissionTable";
import { useEvent } from "../hooks/event";
import { useSubmissionList } from "../hooks/submission";
import UserLayout from "../layouts/userLayout/UserLayout";

const SubmissionList: React.FC = () => {
const { getSubmissionList } = useSubmissionList();
useEvent();
// useEvent();

return (
<UserLayout>
Expand Down

0 comments on commit a7760ad

Please sign in to comment.