Skip to content

Commit

Permalink
Merge pull request #122 from wafflestudio/main
Browse files Browse the repository at this point in the history
문제 풀이 에러 핸들링 로직 개선 / 리스트 스타일 개선
  • Loading branch information
minkyu97 authored Aug 14, 2024
2 parents 0c1c07a + 5f51ed9 commit ff19d16
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/apis/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const getProblemSubmissionV2 = (problem_id: number) =>
| { type: "skip"; data: { items: [] } }
| { type: "message"; data: { items: ProblemSubmissionResultV2[] } }
| { type: "error"; data: { detail: string } }
| { type: "unknown"; data: unknown }
>(
`/v2/problems/${problem_id}/submission`,
{}, // body
Expand Down
12 changes: 10 additions & 2 deletions src/apis/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,20 @@ export const sseRequest = <Response extends { type: string; data: unknown }>(
for await (const event of parseEvent(reader)) {
yield {
type: event.type,
data: JSON.parse(event.data),
data: tryParseData(event.data),
} as Response;
}
},
});

function tryParseData(data: string) {
try {
return JSON.parse(data);
} catch {
return data;
}
}

async function* parseLine(reader: ReadableStreamDefaultReader<string>) {
let lastLine = "";
while (true) {
Expand All @@ -156,7 +164,7 @@ async function* parseEvent(reader: ReadableStreamDefaultReader<string>) {
if (line.length > 0) lines.push(line);
else {
const type = removeFirstSpace(
lines.find((line) => line.startsWith("event:"))?.slice(6) ?? " " + line,
lines.find((line) => line.startsWith("event:"))?.slice(6) ?? "unknown",
);
const data = lines
.filter((line) => line.startsWith("data:"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ const MarkdownStyledWrapper = styled.div`
ul,
ol {
list-style: disc outside none !important;
.li {
}
font-size: 1.8rem;
line-height: 160%;
}
code {
background: rgba(135, 131, 120, 0.15);
Expand Down
35 changes: 24 additions & 11 deletions src/pages/SolveV2.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { useRef, useState } from "react";
import { flushSync } from "react-dom";
import { Link, useParams } from "react-router-dom";
import styled from "styled-components";
import ProblemDescription from "../components/solve/ProblemDescription/ProblemDescription.tsx";
import CodeEditor from "../components/solve/CodeEditor/index.tsx";
import TestResultConsole from "../components/solve/TestResultConsoleV2.tsx";
import DragResizable from "../components/solve/DragResizable.tsx";
import { useRef, useState } from "react";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import {
getProblemById,
getProblemSubmissionV2,
postProblemSubmissionV2,
} from "../apis/problem.ts";
import CodeEditor from "../components/solve/CodeEditor/index.tsx";
import { useCodeRef } from "../components/solve/CodeEditor/useCode.tsx";
import {
boilerplates,
languageCodesV2,
useLanguage,
} from "../components/solve/CodeEditor/useLanguage.tsx";
import { useCodeRef } from "../components/solve/CodeEditor/useCode.tsx";
import DragResizable from "../components/solve/DragResizable.tsx";
import ProblemDescription from "../components/solve/ProblemDescription/ProblemDescription.tsx";
import { useCustomTestCases } from "../components/solve/ProblemDescription/useCustomTestCases.tsx";
import { ProblemSubmissionResultV2 } from "../types/apiTypes.ts";
import TestResultConsole from "../components/solve/TestResultConsoleV2.tsx";
import { unreachable } from "../lib/unreachable.ts";
import { flushSync } from "react-dom";
import { ProblemSubmissionResultV2 } from "../types/apiTypes.ts";

export default function Solve() {
const params = useParams();
Expand Down Expand Up @@ -71,6 +71,13 @@ export default function Solve() {
expected_output: t.output,
}))
: [],
}).catch((e: Response) => {
return e.json().then((data: any) => {
if (data.detail) throw Error(data.detail);
else {
throw Error("코드 제출에 실패했습니다. 운영팀에게 문의해주세요.");
}
});
});
res
.then(() => getProblemSubmissionV2(problemNumber))
Expand Down Expand Up @@ -100,14 +107,20 @@ export default function Solve() {
});
}
break;
case "unknown":
console.error(`Unknown data: ${data}`);
break;
default:
unreachable(type);
}
}
})
.catch((e) => {
console.error(e);
alert("모집이 기간이 아닙니다.");
if (e instanceof Error) {
alert(e.message);
} else {
alert("채점 결과 조회에 실패했습니다. 운영팀에게 문의 바랍니다.");
}
});
setIsSubmitting(false);
};
Expand Down

0 comments on commit ff19d16

Please sign in to comment.