@@ -11,16 +11,19 @@ import {
11
11
import classes from "./index.module.css" ;
12
12
import { useMatch } from "../../contexts/MatchContext" ;
13
13
import { USE_MATCH_ERROR_MESSAGE } from "../../utils/constants" ;
14
- import { useEffect , useReducer } from "react" ;
14
+ import { useEffect , useReducer , useState } from "react" ;
15
15
import Loader from "../../components/Loader" ;
16
16
import ServerError from "../../components/ServerError" ;
17
17
import reducer , {
18
18
getQuestionById ,
19
19
initialState ,
20
20
} from "../../reducers/questionReducer" ;
21
21
import QuestionDetailComponent from "../../components/QuestionDetail" ;
22
+ import { Navigate } from "react-router-dom" ;
22
23
23
24
const CollabSandbox : React . FC = ( ) => {
25
+ const [ showErrorScreen , setShowErrorScreen ] = useState < boolean > ( false ) ;
26
+
24
27
const match = useMatch ( ) ;
25
28
if ( ! match ) {
26
29
throw new Error ( USE_MATCH_ERROR_MESSAGE ) ;
@@ -40,6 +43,10 @@ const CollabSandbox: React.FC = () => {
40
43
const { selectedQuestion } = state ;
41
44
42
45
useEffect ( ( ) => {
46
+ if ( ! partner ) {
47
+ return ;
48
+ }
49
+
43
50
verifyMatchStatus ( ) ;
44
51
45
52
if ( ! questionId ) {
@@ -54,11 +61,29 @@ const CollabSandbox: React.FC = () => {
54
61
// eslint-disable-next-line react-hooks/exhaustive-deps
55
62
} , [ ] ) ;
56
63
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
+
57
78
if ( loading ) {
58
79
return < Loader /> ;
59
80
}
60
81
61
- if ( ! partner || ! questionId || ! selectedQuestion ) {
82
+ if ( ! partner ) {
83
+ return < Navigate to = "/home" replace /> ;
84
+ }
85
+
86
+ if ( showErrorScreen ) {
62
87
return (
63
88
< ServerError
64
89
title = "Oops, match ended..."
@@ -67,6 +92,10 @@ const CollabSandbox: React.FC = () => {
67
92
) ;
68
93
}
69
94
95
+ if ( ! selectedQuestion ) {
96
+ return < Loader /> ;
97
+ }
98
+
70
99
return (
71
100
< AppMargin classname = { `${ classes . fullheight } ${ classes . flex } ` } >
72
101
{ /* <Stack spacing={2} alignItems={"center"}>
0 commit comments