Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some render problem #51

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/SubmissionDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { PrismLight as SyntaxHighlighter } from "react-syntax-highlighter";
import { PrismAsyncLight as SyntaxHighlighter } from "react-syntax-highlighter";
import { oneDark } from "react-syntax-highlighter/dist/cjs/styles/prism";
import { SubmissionServiceModel } from "../typings/submission";
import { CopyToClipboard } from "react-copy-to-clipboard";
Expand Down Expand Up @@ -29,7 +29,7 @@ const SubmissionDetail: React.FC<SubmissionDetailProps> = (props) => {
</thead>
<tbody>
<tr className="bg-base-200">
<td className="border-r border-t">{props.data.uid}</td>
<td className="border-r border-t">{props.data.UID}</td>
<td className="border-l border-t">{props.data.problem.slug}</td>
<td className="border-l border-t">{props.data.language}</td>
<td className="border-l border-t">
Expand Down
4 changes: 2 additions & 2 deletions src/components/SubmissionTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const SubmissionTable: React.FC<SubmissionTableProps> = (props) => {
</tr>
</thead>
<tbody>
{props.data.map((submission) => (
<tr className="hover" onClick={() => navigate(submission.uid)}>
{props.data.map((submission, idx) => (
<tr className="hover" onClick={() => navigate(submission.UID)} key={idx}>
<th>{submission.problem.title}</th>
<td>{submission.user.name}</td>
<td>{submission.language}</td>
Expand Down
11 changes: 8 additions & 3 deletions src/hooks/problem.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { ProblemServiceModel } from "../typings/problem";
import { ProblemService } from "../api/problem";

export const useProblem = (slug: string, fallback?: () => void) => {
const [problem, setProblem] = useState<ProblemServiceModel.Problem | null>(
null,
);
const fallbackRef = useRef(fallback);

useEffect(() => {
fallbackRef.current = fallback;
}, [fallback]);

useEffect(() => {
ProblemService.getProblem(slug)
Expand All @@ -14,9 +19,9 @@ export const useProblem = (slug: string, fallback?: () => void) => {
})
.catch((err) => {
console.log(err);
fallback?.();
fallbackRef.current?.();
});
}, [slug, fallback]);
}, [slug]);

function getProblem() {
return problem;
Expand Down
4 changes: 2 additions & 2 deletions src/mocks/rest/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SubmissionServiceModel } from "../../typings/submission";

const submissions: SubmissionServiceModel.SubmissionInfo[] = [
{
uid: "1",
UID: "1",
user: {
account: "user-1",
name: "User 1",
Expand All @@ -18,7 +18,7 @@ const submissions: SubmissionServiceModel.SubmissionInfo[] = [
status: "finished",
},
{
uid: "2",
UID: "2",
user: {
account: "user-2",
name: "User 2",
Expand Down
2 changes: 1 addition & 1 deletion src/typings/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UserServiceModel } from "./user";

export namespace SubmissionServiceModel {
export interface SubmissionInfo {
uid: string;
UID: string;
user: UserServiceModel.UserInfo;
problem: ProblemServiceModel.ProblemInfo;
language: string;
Expand Down
Loading