@@ -15,12 +15,12 @@ import classes from "./index.module.css";
15
15
import { useCollab } from "../../contexts/CollabContext" ;
16
16
import { useMatch } from "../../contexts/MatchContext" ;
17
17
import {
18
+ COLLAB_CONNECTION_ERROR ,
18
19
USE_COLLAB_ERROR_MESSAGE ,
19
20
USE_MATCH_ERROR_MESSAGE ,
20
21
} from "../../utils/constants" ;
21
22
import { useEffect , useReducer , useState } from "react" ;
22
23
import Loader from "../../components/Loader" ;
23
- import ServerError from "../../components/ServerError" ;
24
24
import reducer , {
25
25
getQuestionById ,
26
26
initialState ,
@@ -32,6 +32,7 @@ import TabPanel from "../../components/TabPanel";
32
32
import TestCase from "../../components/TestCase" ;
33
33
import CodeEditor from "../../components/CodeEditor" ;
34
34
import { CollabSessionData , join , leave } from "../../utils/collabSocket" ;
35
+ import { toast } from "react-toastify" ;
35
36
36
37
// hardcode for now...
37
38
@@ -58,10 +59,10 @@ const testcases: TestCase[] = [
58
59
] ;
59
60
60
61
const CollabSandbox : React . FC = ( ) => {
61
- const [ showErrorScreen , setShowErrorScreen ] = useState < boolean > ( false ) ;
62
62
const [ editorState , setEditorState ] = useState < CollabSessionData | null > (
63
63
null
64
64
) ;
65
+ const [ isConnecting , setIsConnecting ] = useState < boolean > ( true ) ;
65
66
66
67
const match = useMatch ( ) ;
67
68
if ( ! match ) {
@@ -92,10 +93,6 @@ const CollabSandbox: React.FC = () => {
92
93
const [ selectedTestcase , setSelectedTestcase ] = useState ( 0 ) ;
93
94
94
95
useEffect ( ( ) => {
95
- if ( ! partner ) {
96
- return ;
97
- }
98
-
99
96
verifyMatchStatus ( ) ;
100
97
101
98
if ( ! questionId ) {
@@ -114,10 +111,12 @@ const CollabSandbox: React.FC = () => {
114
111
if ( editorState . ready ) {
115
112
setEditorState ( editorState ) ;
116
113
} else {
117
- setShowErrorScreen ( true ) ;
114
+ toast . error ( COLLAB_CONNECTION_ERROR ) ;
115
+ setIsConnecting ( false ) ;
118
116
}
119
117
} catch ( error ) {
120
- console . error ( "Error connecting to collab session: " , error ) ;
118
+ toast . error ( COLLAB_CONNECTION_ERROR ) ;
119
+ setIsConnecting ( false ) ;
121
120
}
122
121
} ;
123
122
@@ -128,37 +127,20 @@ const CollabSandbox: React.FC = () => {
128
127
// eslint-disable-next-line react-hooks/exhaustive-deps
129
128
} , [ ] ) ;
130
129
131
- useEffect ( ( ) => {
132
- let timeout : number | undefined ;
133
-
134
- if ( ! selectedQuestion ) {
135
- timeout = setTimeout ( ( ) => {
136
- setShowErrorScreen ( true ) ;
137
- } , 2000 ) ;
138
- } else {
139
- setShowErrorScreen ( false ) ;
140
- }
141
-
142
- return ( ) => clearTimeout ( timeout ) ;
143
- } , [ selectedQuestion ] ) ;
144
-
145
130
if ( loading ) {
146
131
return < Loader /> ;
147
132
}
148
133
149
- if ( ! matchUser || ! partner || ! matchCriteria || ! getMatchId ( ) ) {
134
+ if (
135
+ ! matchUser ||
136
+ ! partner ||
137
+ ! matchCriteria ||
138
+ ! getMatchId ( ) ||
139
+ ! isConnecting
140
+ ) {
150
141
return < Navigate to = "/home" replace /> ;
151
142
}
152
143
153
- if ( showErrorScreen ) {
154
- return (
155
- < ServerError
156
- title = "Oops, collaboration session ended..."
157
- subtitle = "Unfortunately, the session has ended due to a connection loss 😥"
158
- />
159
- ) ;
160
- }
161
-
162
144
if ( ! selectedQuestion || ! editorState ) {
163
145
return < Loader /> ;
164
146
}
@@ -234,8 +216,7 @@ const CollabSandbox: React.FC = () => {
234
216
width : "100%" ,
235
217
minHeight : "44vh" ,
236
218
maxHeight : "44vh" ,
237
- paddingTop : theme . spacing ( 2 ) ,
238
- paddingBottom : theme . spacing ( 2 ) ,
219
+ paddingTop : theme . spacing ( 1 ) ,
239
220
} ) }
240
221
>
241
222
< CodeEditor
@@ -256,12 +237,13 @@ const CollabSandbox: React.FC = () => {
256
237
/>
257
238
</ Box >
258
239
< Box
259
- sx = { {
240
+ sx = { ( theme ) => ( {
260
241
flex : 1 ,
261
242
maxHeight : "44vh" ,
262
243
display : "flex" ,
263
244
flexDirection : "column" ,
264
- } }
245
+ paddingTop : theme . spacing ( 1 ) ,
246
+ } ) }
265
247
>
266
248
< Tabs
267
249
value = { selectedTab }
0 commit comments