Skip to content

Commit b236251

Browse files
committed
feat: add loading to submission
1 parent eb946d7 commit b236251

File tree

2 files changed

+65
-29
lines changed

2 files changed

+65
-29
lines changed

apps/frontend/src/app/question/[id]/page.tsx

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22
import Header from "@/components/Header/header";
3-
import { Col, Layout, message, PaginationProps, Row, Table } from "antd";
3+
import { Col, Layout, message, PaginationProps, Row, Spin, Table } from "antd";
44
import { Content } from "antd/es/layout/layout";
55
import { CodeOutlined, HistoryOutlined } from "@ant-design/icons";
66
import "./styles.scss";
@@ -65,6 +65,7 @@ export default function QuestionPage() {
6565
useState<History[]>();
6666
const [submission, setSubmission] = useState<Submission>();
6767
const [isHistoryLoading, setIsHistoryLoading] = useState<boolean>(true);
68+
const [isSubmissionLoading, setIsSubmissionLoading] = useState<boolean>(true);
6869
const [currentSubmissionId, setCurrentSubmissionId] = useState<
6970
string | undefined
7071
>(historyDocRefId == "" ? undefined : historyDocRefId);
@@ -156,24 +157,28 @@ export default function QuestionPage() {
156157
parent: editorRef.current || undefined,
157158
});
158159

159-
GetHistory(currentSubmissionId).then((data: any) => {
160-
const submittedAt = new Date(data.createdAt);
161-
setSubmission({
162-
submittedAt: submittedAt.toLocaleString("en-US"),
163-
language: data.language,
164-
matchedUser:
165-
username == data.matchedUser ? data.user : data.matchedUser,
166-
otherUser: data.user,
167-
historyDocRefId: data.historyDocRefId,
168-
code: data.code,
169-
});
160+
setIsSubmissionLoading(true);
161+
GetHistory(currentSubmissionId)
162+
.then((data: any) => {
163+
const submittedAt = new Date(data.createdAt);
164+
setSubmission({
165+
submittedAt: submittedAt.toLocaleString("en-US"),
166+
language: data.language,
167+
matchedUser:
168+
username == data.matchedUser ? data.user : data.matchedUser,
169+
otherUser: data.user,
170+
historyDocRefId: data.historyDocRefId,
171+
code: data.code,
172+
});
173+
setIsSubmissionLoading(false);
170174

171-
view.dispatch(
172-
state.update({
173-
changes: { from: 0, to: state.doc.length, insert: data.code },
174-
})
175-
);
176-
});
175+
view.dispatch(
176+
state.update({
177+
changes: { from: 0, to: state.doc.length, insert: data.code },
178+
})
179+
);
180+
})
181+
.finally(() => {});
177182

178183
return () => {
179184
// Cleanup on component unmount
@@ -258,7 +263,25 @@ export default function QuestionPage() {
258263
{currentSubmissionId && (
259264
<Row className="code-row">
260265
<div className="code-container">
261-
<>
266+
{isSubmissionLoading && (
267+
<div
268+
style={{
269+
display: "flex",
270+
justifyContent: "center",
271+
alignItems: "center",
272+
height: "100%",
273+
}}
274+
>
275+
<Spin />
276+
</div>
277+
)}
278+
<div
279+
style={{
280+
visibility: `${
281+
isSubmissionLoading ? "hidden" : "visible"
282+
}`,
283+
}}
284+
>
262285
<div className="code-top-container">
263286
<div className="code-title">
264287
<CodeOutlined className="title-icons" />
@@ -271,23 +294,34 @@ export default function QuestionPage() {
271294
style={{
272295
margin: "10px",
273296
display: "flex",
297+
justifyContent: "space-between",
274298
flexDirection: "row",
275299
}}
276300
>
277301
<div className="submission-header-detail">
278-
Submitted at: {submission?.submittedAt || "-"}
302+
<div style={{ fontWeight: "bold" }}>
303+
Submitted at:&nbsp;
304+
</div>
305+
<div>{submission?.submittedAt || "-"}</div>
279306
</div>
280307
<div className="submission-header-detail">
281-
Language: {submission?.language || "-"}
308+
<div style={{ fontWeight: "bold" }}>
309+
Language:&nbsp;
310+
</div>
311+
<div>{submission?.language || "-"}</div>
282312
</div>
283313
<div className="submission-header-detail">
284-
Matched with:{" "}
285-
{submission?.matchedUser
286-
? // Check to ensure that matched user is correct, otherwise swap with otherUser
287-
username == submission.matchedUser
288-
? submission.otherUser
289-
: submission.matchedUser
290-
: "-"}
314+
<div style={{ fontWeight: "bold" }}>
315+
Matched with:&nbsp;
316+
</div>
317+
<div>
318+
{submission?.matchedUser
319+
? // Check to ensure that matched user is correct, otherwise swap with otherUser
320+
username == submission.matchedUser
321+
? submission.otherUser
322+
: submission.matchedUser
323+
: "-"}
324+
</div>
291325
</div>
292326
</div>
293327

@@ -307,7 +341,7 @@ export default function QuestionPage() {
307341
}}
308342
></div>
309343
</div>
310-
</>
344+
</div>
311345
</div>
312346
</Row>
313347
)}

apps/frontend/src/app/question/[id]/styles.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,7 @@
140140

141141
.submission-header-detail {
142142
font-weight: normal;
143+
display: flex;
144+
flex-direction: row;
143145
padding: 0px 10px 0px 10px;
144146
}

0 commit comments

Comments
 (0)