Skip to content

Commit 9f350d2

Browse files
committed
Fix lint error and bugs in specific scenarios
1 parent 2d59d81 commit 9f350d2

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

frontend/src/components/CollabSessionControls/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const CollabSessionControls: React.FC = () => {
1313
const [time, setTime] = useState<number>(0);
1414

1515
useEffect(() => {
16-
let intervalId = setInterval(
16+
const intervalId = setInterval(
1717
() => setTime((prevTime) => prevTime + 1),
1818
1000
1919
);

frontend/src/contexts/MatchContext.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
281281
const initMatchedListeners = () => {
282282
matchSocket.on(MatchEvents.MATCH_SUCCESSFUL, (id: string) => {
283283
setMatchPending(false);
284-
appNavigate(MatchPaths.COLLAB);
285284
setQuestionId(id);
285+
appNavigate(MatchPaths.COLLAB);
286286
});
287287

288288
matchSocket.on(MatchEvents.MATCH_UNSUCCESSFUL, () => {
@@ -302,6 +302,7 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
302302
const initCollabListeners = () => {
303303
matchSocket.on(MatchEvents.MATCH_ENDED, () => {
304304
toast.error(MATCH_ENDED_MESSAGE);
305+
setIsEndSessionModalOpen(false);
305306
appNavigate(MatchPaths.HOME);
306307
});
307308
};
@@ -501,8 +502,8 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
501502
};
502503

503504
const handleConfirmEndSession = () => {
504-
stopMatch();
505505
setIsEndSessionModalOpen(false);
506+
stopMatch();
506507
};
507508

508509
return (

frontend/src/pages/CollabSandbox/index.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ import {
1111
import classes from "./index.module.css";
1212
import { useMatch } from "../../contexts/MatchContext";
1313
import { USE_MATCH_ERROR_MESSAGE } from "../../utils/constants";
14-
import { useEffect, useReducer } from "react";
14+
import { useEffect, useReducer, useState } from "react";
1515
import Loader from "../../components/Loader";
1616
import ServerError from "../../components/ServerError";
1717
import reducer, {
1818
getQuestionById,
1919
initialState,
2020
} from "../../reducers/questionReducer";
2121
import QuestionDetailComponent from "../../components/QuestionDetail";
22+
import { Navigate } from "react-router-dom";
2223

2324
const CollabSandbox: React.FC = () => {
25+
const [showErrorScreen, setShowErrorScreen] = useState<boolean>(false);
26+
2427
const match = useMatch();
2528
if (!match) {
2629
throw new Error(USE_MATCH_ERROR_MESSAGE);
@@ -40,6 +43,10 @@ const CollabSandbox: React.FC = () => {
4043
const { selectedQuestion } = state;
4144

4245
useEffect(() => {
46+
if (!partner) {
47+
return;
48+
}
49+
4350
verifyMatchStatus();
4451

4552
if (!questionId) {
@@ -54,11 +61,29 @@ const CollabSandbox: React.FC = () => {
5461
// eslint-disable-next-line react-hooks/exhaustive-deps
5562
}, []);
5663

64+
useEffect(() => {
65+
let timeout: number | undefined;
66+
67+
if (!selectedQuestion) {
68+
timeout = setTimeout(() => {
69+
setShowErrorScreen(true);
70+
}, 2000);
71+
} else {
72+
setShowErrorScreen(false);
73+
}
74+
75+
return () => clearTimeout(timeout);
76+
}, [selectedQuestion]);
77+
5778
if (loading) {
5879
return <Loader />;
5980
}
6081

61-
if (!partner || !questionId || !selectedQuestion) {
82+
if (!partner) {
83+
return <Navigate to="/home" replace />;
84+
}
85+
86+
if (showErrorScreen) {
6287
return (
6388
<ServerError
6489
title="Oops, match ended..."
@@ -67,6 +92,10 @@ const CollabSandbox: React.FC = () => {
6792
);
6893
}
6994

95+
if (!selectedQuestion) {
96+
return <Loader />;
97+
}
98+
7099
return (
71100
<AppMargin classname={`${classes.fullheight} ${classes.flex}`}>
72101
{/* <Stack spacing={2} alignItems={"center"}>

0 commit comments

Comments
 (0)