Skip to content

Commit 63de714

Browse files
authored
Merge pull request #70 from guanquann/frontend/lint
Fix frontend lint issues
2 parents 8030c71 + 34f8c7d commit 63de714

File tree

6 files changed

+45
-23
lines changed

6 files changed

+45
-23
lines changed

frontend/src/components/NoDirectAccessRoutes/index.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
import { Navigate, Outlet, useLocation, useNavigate } from "react-router-dom";
2-
import React from "react";
3-
4-
export const useAppNavigate = () => {
5-
const navigate = useNavigate();
6-
7-
const appNavigate = (path: string) => {
8-
navigate(path, {
9-
replace: location.pathname !== "/home",
10-
state: { from: "app-navigation" },
11-
});
12-
};
13-
14-
return appNavigate;
15-
};
1+
import { Navigate, Outlet, useLocation } from "react-router-dom";
162

173
const NoDirectAccessRoutes: React.FC = () => {
184
const location = useLocation();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { useNavigate } from "react-router-dom";
2+
3+
export const useAppNavigate = () => {
4+
const navigate = useNavigate();
5+
6+
const appNavigate = (path: string) => {
7+
navigate(path, {
8+
replace: location.pathname !== "/home",
9+
state: { from: "app-navigation" },
10+
});
11+
};
12+
13+
return appNavigate;
14+
};
15+
16+
export default useAppNavigate;

frontend/src/contexts/MatchContext.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from "../utils/constants";
1414
import { useAuth } from "./AuthContext";
1515
import { toast } from "react-toastify";
16-
import { useAppNavigate } from "../components/NoDirectAccessRoutes";
16+
import useAppNavigate from "../components/UseAppNavigate";
1717

1818
type MatchUser = {
1919
id: string;
@@ -98,7 +98,8 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
9898
throw new Error(USE_AUTH_ERROR_MESSAGE);
9999
}
100100
const { user } = auth;
101-
const [matchUser, _setMatchUser] = useState<MatchUser | null>(
101+
102+
const [matchUser] = useState<MatchUser | null>(
102103
user
103104
? {
104105
id: user.id,
@@ -136,6 +137,7 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
136137
closeSocketConnection();
137138
window.removeEventListener("beforeunload", () => closeSocketConnection());
138139
};
140+
// eslint-disable-next-line react-hooks/exhaustive-deps
139141
}, [matchUser?.id, location.pathname]);
140142

141143
const resetMatchStates = () => {
@@ -220,7 +222,11 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
220222
const initMatchRequestListeners = () => {
221223
matchSocket.on(MatchEvents.MATCH_FOUND, ({ matchId, user1, user2 }) => {
222224
setMatchId(matchId);
223-
matchUser?.id === user1.id ? setPartner(user2) : setPartner(user1);
225+
if (matchUser?.id === user1.id) {
226+
setPartner(user2);
227+
} else {
228+
setPartner(user1);
229+
}
224230
setMatchPending(true);
225231
appNavigate(MatchPaths.MATCHED);
226232
});
@@ -237,7 +243,11 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
237243
const initMatchingListeners = () => {
238244
matchSocket.on(MatchEvents.MATCH_FOUND, ({ matchId, user1, user2 }) => {
239245
setMatchId(matchId);
240-
matchUser?.id === user1.id ? setPartner(user2) : setPartner(user1);
246+
if (matchUser?.id === user1.id) {
247+
setPartner(user2);
248+
} else {
249+
setPartner(user1);
250+
}
241251
setMatchPending(true);
242252
appNavigate(MatchPaths.MATCHED);
243253
});
@@ -256,7 +266,11 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
256266

257267
matchSocket.on(MatchEvents.MATCH_FOUND, ({ matchId, user1, user2 }) => {
258268
setMatchId(matchId);
259-
matchUser?.id === user1.id ? setPartner(user2) : setPartner(user1);
269+
if (matchUser?.id === user1.id) {
270+
setPartner(user2);
271+
} else {
272+
setPartner(user1);
273+
}
260274
setMatchPending(true);
261275
appNavigate(MatchPaths.MATCHED);
262276
});

frontend/src/pages/CollabSandbox/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const CollabSandbox: React.FC = () => {
1616

1717
useEffect(() => {
1818
verifyMatchStatus();
19+
// eslint-disable-next-line react-hooks/exhaustive-deps
1920
}, []);
2021

2122
if (loading) {

frontend/src/pages/Matched/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ const Matched: React.FC = () => {
5555

5656
useEffect(() => {
5757
if (timeLeft <= 0) {
58-
accepted
59-
? toast.error(MATCH_UNSUCCESSFUL_MESSAGE)
60-
: toast.error(MATCH_OFFER_TIMEOUT_MESSAGE);
58+
if (accepted) {
59+
toast.error(MATCH_UNSUCCESSFUL_MESSAGE);
60+
} else {
61+
toast.error(MATCH_OFFER_TIMEOUT_MESSAGE);
62+
}
6163
matchOfferTimeout();
6264
}
65+
// eslint-disable-next-line react-hooks/exhaustive-deps
6366
}, [timeLeft]);
6467

6568
if (!matchUser || !partner) {

frontend/src/pages/Matching/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ const Matching: React.FC = () => {
3535
});
3636

3737
return () => clearInterval(timer);
38+
// eslint-disable-next-line react-hooks/exhaustive-deps
3839
}, []);
3940

4041
useEffect(() => {
4142
if (timeLeft <= 0) {
4243
matchingTimeout();
4344
}
45+
// eslint-disable-next-line react-hooks/exhaustive-deps
4446
}, [timeLeft]);
4547

4648
if (!matchCriteria) {

0 commit comments

Comments
 (0)