Skip to content

Commit 6e8d8d5

Browse files
committed
resolve comment issues and add loader to prevent error msg rendering before actual data
1 parent 06b5ae2 commit 6e8d8d5

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

backend/matching-service/.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ RABBITMQ_DEFAULT_PASS=password #comment out if use case is (1)
1414
RABBITMQ_ADDR=amqp://admin:password@rabbitmq:5672 #comment out if use case is (1)
1515

1616
QUESTION_SERVICE_URL=http://question-service:3000/api/questions
17+
18+
QN_HISTORY_SERVICE_URL=http://qn-history-service:3006/api/qnhistories

frontend/src/App.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,7 @@ function App() {
5252
</ProfileContextProvider>
5353
}
5454
/>
55-
<Route
56-
path="profile/:userId/:qnHistoryId"
57-
element={
58-
<AuthProvider>
59-
<QuestionHistoryDetail />
60-
</AuthProvider>
61-
}
62-
/>
55+
<Route path="profile/:userId/:qnHistoryId" element={<QuestionHistoryDetail />} />
6356
<Route path="matching" element={<ProtectedRoutes />}>
6457
<Route element={<NoDirectAccessRoutes />}>
6558
<Route index element={<Matching />} />

frontend/src/pages/Profile/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ import {
1616
import qnHistoryReducer, { getQnHistoryList, initialQHState } from "../../reducers/qnHistoryReducer";
1717
import { grey } from "@mui/material/colors";
1818
import { convertDateString } from "../../utils/sessionTime";
19+
import Loader from "../../components/Loader";
1920

2021
const rowsPerPage = 10;
2122

2223
const ProfilePage: React.FC = () => {
2324
const [page, setPage] = useState<number>(0);
2425
const [state, dispatch] = useReducer(qnHistoryReducer, initialQHState);
26+
const [loading, setLoading] = useState<boolean>(true);
2527
const navigate = useNavigate();
2628

2729
const { userId } = useParams<{ userId: string }>();
@@ -47,11 +49,14 @@ const ProfilePage: React.FC = () => {
4749
} = profile;
4850

4951
useEffect(() => {
52+
setLoading(true);
5053
if (!userId) {
54+
setTimeout(() => setLoading(false), 500);
5155
return;
5256
}
5357

5458
fetchUser(userId);
59+
setTimeout(() => setLoading(false), 500);
5560
// eslint-disable-next-line react-hooks/exhaustive-deps
5661
}, [userId]);
5762

@@ -69,6 +74,10 @@ const ProfilePage: React.FC = () => {
6974
// eslint-disable-next-line react-hooks/exhaustive-deps
7075
useEffect(() => updateQnHistoryList(), [page]);
7176

77+
if (loading) {
78+
return <Loader />;
79+
}
80+
7281
if (!user) {
7382
return (
7483
<ServerError

frontend/src/pages/QuestionHistoryDetail/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useReducer } from "react";
1+
import { useEffect, useReducer, useState } from "react";
22
import { useNavigate, useParams } from "react-router-dom";
33
import AppMargin from "../../components/AppMargin";
44
import ServerError from "../../components/ServerError";
@@ -14,11 +14,13 @@ import { grey } from "@mui/material/colors";
1414
import { convertDateString } from "../../utils/sessionTime";
1515
import { useAuth } from "../../contexts/AuthContext";
1616
import { USE_AUTH_ERROR_MESSAGE } from "../../utils/constants";
17+
import Loader from "../../components/Loader";
1718

1819
const QuestionHistoryDetail: React.FC = () => {
1920
const { qnHistoryId } = useParams<{ qnHistoryId: string }>();
2021
const [qnhistState, qnhistDispatch] = useReducer(qnHistoryReducer, initialQHState);
2122
const [qnState, qnDispatch] = useReducer(reducer, initialState);
23+
const [loading, setLoading] = useState<boolean>(true);
2224
const navigate = useNavigate();
2325
const auth = useAuth();
2426

@@ -44,6 +46,7 @@ const QuestionHistoryDetail: React.FC = () => {
4446
if (qnhistState.selectedQnHistory) {
4547
getQuestionById(qnhistState.selectedQnHistory.questionId, qnDispatch);
4648
}
49+
setTimeout(() => setLoading(false), 500);
4750
}, [qnhistState])
4851

4952

@@ -55,6 +58,10 @@ const QuestionHistoryDetail: React.FC = () => {
5558
}
5659
}
5760

61+
if (loading) {
62+
return <Loader />;
63+
}
64+
5865
if (!qnhistState.selectedQnHistory) {
5966
if (qnhistState.selectedQnHistoryError) {
6067
return (
@@ -72,7 +79,7 @@ const QuestionHistoryDetail: React.FC = () => {
7279

7380
return (
7481
<AppMargin>
75-
<IconButton sx={{marginTop: 2}} onClick={() => navigate(-1)}>
82+
<IconButton sx={{marginTop: 2}} onClick={() => navigate(`/profile/${user?.id}`)}>
7683
<ArrowBack />
7784
</IconButton>
7885
<Typography variant="h2" style={{marginTop: 20, marginBottom: 20}}>Latest submission details</Typography>

0 commit comments

Comments
 (0)