@@ -31,7 +31,18 @@ import CollaborativeEditor, {
31
31
} from "@/components/CollaborativeEditor/CollaborativeEditor" ;
32
32
import { CreateHistory } from "@/app/services/history" ;
33
33
import { WebrtcProvider } from "y-webrtc" ;
34
- import { ExecuteVisibleAndCustomTests , ExecuteVisibleAndHiddenTestsAndSubmit , ExecutionResults , GetVisibleTests , isTestResult , SubmissionHiddenTestResultsAndStatus , SubmissionResults , Test , TestData , TestResult } from "@/app/services/execute" ;
34
+ import {
35
+ ExecuteVisibleAndCustomTests ,
36
+ ExecuteVisibleAndHiddenTestsAndSubmit ,
37
+ ExecutionResults ,
38
+ GetVisibleTests ,
39
+ isTestResult ,
40
+ SubmissionHiddenTestResultsAndStatus ,
41
+ SubmissionResults ,
42
+ Test ,
43
+ TestData ,
44
+ TestResult ,
45
+ } from "@/app/services/execute" ;
35
46
import { QuestionDetailFull } from "@/components/question/QuestionDetailFull/QuestionDetailFull" ;
36
47
import VideoPanel from "@/components/VideoPanel/VideoPanel" ;
37
48
@@ -69,15 +80,17 @@ export default function CollaborationPage(props: CollaborationProps) {
69
80
) ;
70
81
const [ currentUser , setCurrentUser ] = useState < string | undefined > ( undefined ) ;
71
82
const [ matchedUser , setMatchedUser ] = useState < string > ( "Loading..." ) ;
72
- const [ sessionDuration , setSessionDuration ] = useState < number > ( ( ) => {
73
- const storedTime = localStorage . getItem ( "session-duration" ) ;
74
- return storedTime ? parseInt ( storedTime ) : 0 ;
75
- } ) ; // State for count-up timer (TODO: currently using localstorage to store time, change to db stored time in the future)
83
+ const [ sessionDuration , setSessionDuration ] = useState < number > ( 0 ) ; // State for count-up timer (TODO: currently using localstorage to store time, change to db stored time in the future)
76
84
const stopwatchRef = useRef < NodeJS . Timeout | null > ( null ) ;
77
85
const [ matchedTopics , setMatchedTopics ] = useState < string [ ] | undefined > (
78
86
undefined
79
87
) ;
80
88
89
+ useEffect ( ( ) => {
90
+ const storedTime = localStorage . getItem ( "session-duration" ) ;
91
+ setSessionDuration ( storedTime ? parseInt ( storedTime ) : 0 ) ;
92
+ } , [ ] ) ;
93
+
81
94
// Chat states
82
95
const [ messageToSend , setMessageToSend ] = useState < string | undefined > (
83
96
undefined
@@ -89,8 +102,12 @@ export default function CollaborationPage(props: CollaborationProps) {
89
102
) ;
90
103
const [ visibleTestCases , setVisibleTestCases ] = useState < Test [ ] > ( [ ] ) ;
91
104
const [ isLoadingTestCase , setIsLoadingTestCase ] = useState < boolean > ( false ) ;
92
- const [ isLoadingSubmission , setIsLoadingSubmission ] = useState < boolean > ( false ) ;
93
- const [ submissionHiddenTestResultsAndStatus , setSubmissionHiddenTestResultsAndStatus ] = useState < SubmissionHiddenTestResultsAndStatus | undefined > ( undefined ) ;
105
+ const [ isLoadingSubmission , setIsLoadingSubmission ] =
106
+ useState < boolean > ( false ) ;
107
+ const [
108
+ submissionHiddenTestResultsAndStatus ,
109
+ setSubmissionHiddenTestResultsAndStatus ,
110
+ ] = useState < SubmissionHiddenTestResultsAndStatus | undefined > ( undefined ) ;
94
111
95
112
// End Button Modal state
96
113
const [ isModalOpen , setIsModalOpen ] = useState < boolean > ( false ) ;
@@ -151,7 +168,7 @@ export default function CollaborationPage(props: CollaborationProps) {
151
168
type : "info" ,
152
169
content : message ,
153
170
} ) ;
154
- }
171
+ } ;
155
172
156
173
const sendSubmissionResultsToMatchedUser = ( data : SubmissionResults ) => {
157
174
if ( ! providerRef . current ) {
@@ -161,7 +178,7 @@ export default function CollaborationPage(props: CollaborationProps) {
161
178
submissionResults : data ,
162
179
id : Date . now ( ) ,
163
180
} ) ;
164
- }
181
+ } ;
165
182
166
183
const sendExecutingStateToMatchedUser = ( executing : boolean ) => {
167
184
if ( ! providerRef . current ) {
@@ -171,7 +188,7 @@ export default function CollaborationPage(props: CollaborationProps) {
171
188
executing : executing ,
172
189
id : Date . now ( ) ,
173
190
} ) ;
174
- }
191
+ } ;
175
192
176
193
const sendSubmittingStateToMatchedUser = ( submitting : boolean ) => {
177
194
if ( ! providerRef . current ) {
@@ -181,7 +198,7 @@ export default function CollaborationPage(props: CollaborationProps) {
181
198
submitting : submitting ,
182
199
id : Date . now ( ) ,
183
200
} ) ;
184
- }
201
+ } ;
185
202
186
203
const sendExecutionResultsToMatchedUser = ( data : ExecutionResults ) => {
187
204
if ( ! providerRef . current ) {
@@ -191,60 +208,54 @@ export default function CollaborationPage(props: CollaborationProps) {
191
208
executionResults : data ,
192
209
id : Date . now ( ) ,
193
210
} ) ;
194
- }
211
+ } ;
195
212
196
213
const updateSubmissionResults = ( data : SubmissionResults ) => {
197
214
setSubmissionHiddenTestResultsAndStatus ( {
198
215
hiddenTestResults : data . hiddenTestResults ,
199
216
status : data . status ,
200
217
} ) ;
201
218
setVisibleTestCases ( data . visibleTestResults ) ;
202
- }
219
+ } ;
203
220
204
221
const updateExecutionResults = ( data : ExecutionResults ) => {
205
222
setVisibleTestCases ( data . visibleTestResults ) ;
206
- }
223
+ } ;
207
224
208
225
const handleRunTestCases = async ( ) => {
209
226
if ( ! questionDocRefId ) {
210
227
throw new Error ( "Question ID not found" ) ;
211
228
}
212
229
setIsLoadingTestCase ( true ) ;
213
230
sendExecutingStateToMatchedUser ( true ) ;
214
- const data = await ExecuteVisibleAndCustomTests (
215
- questionDocRefId ,
216
- {
217
- code : code ,
218
- language : selectedLanguage ,
219
- customTestCases : "" ,
220
- }
221
- ) ;
231
+ const data = await ExecuteVisibleAndCustomTests ( questionDocRefId , {
232
+ code : code ,
233
+ language : selectedLanguage ,
234
+ customTestCases : "" ,
235
+ } ) ;
222
236
setVisibleTestCases ( data . visibleTestResults ) ;
223
- infoMessage ( "Test cases executed. Review the results below." )
237
+ infoMessage ( "Test cases executed. Review the results below." ) ;
224
238
sendExecutionResultsToMatchedUser ( data ) ;
225
239
setIsLoadingTestCase ( false ) ;
226
240
sendExecutingStateToMatchedUser ( false ) ;
227
- }
241
+ } ;
228
242
229
243
const handleSubmitCode = async ( ) => {
230
244
if ( ! questionDocRefId ) {
231
245
throw new Error ( "Question ID not found" ) ;
232
246
}
233
247
setIsLoadingSubmission ( true ) ;
234
248
sendSubmittingStateToMatchedUser ( true ) ;
235
- const data = await ExecuteVisibleAndHiddenTestsAndSubmit (
236
- questionDocRefId ,
237
- {
238
- code : code ,
239
- language : selectedLanguage ,
240
- user : currentUser ?? "" ,
241
- matchedUser : matchedUser ?? "" ,
242
- matchedTopics : matchedTopics ?? [ ] ,
243
- title : questionTitle ?? "" ,
244
- questionDifficulty : complexity ?? "" ,
245
- questionTopics : categories ,
246
- }
247
- ) ;
249
+ const data = await ExecuteVisibleAndHiddenTestsAndSubmit ( questionDocRefId , {
250
+ code : code ,
251
+ language : selectedLanguage ,
252
+ user : currentUser ?? "" ,
253
+ matchedUser : matchedUser ?? "" ,
254
+ matchedTopics : matchedTopics ?? [ ] ,
255
+ title : questionTitle ?? "" ,
256
+ questionDifficulty : complexity ?? "" ,
257
+ questionTopics : categories ,
258
+ } ) ;
248
259
setVisibleTestCases ( data . visibleTestResults ) ;
249
260
setSubmissionHiddenTestResultsAndStatus ( {
250
261
hiddenTestResults : data . hiddenTestResults ,
@@ -254,7 +265,7 @@ export default function CollaborationPage(props: CollaborationProps) {
254
265
successMessage ( "Code saved successfully!" ) ;
255
266
setIsLoadingSubmission ( false ) ;
256
267
sendSubmittingStateToMatchedUser ( false ) ;
257
- }
268
+ } ;
258
269
259
270
const handleCodeChange = ( code : string ) => {
260
271
setCode ( code ) ;
@@ -317,9 +328,7 @@ export default function CollaborationPage(props: CollaborationProps) {
317
328
label : (
318
329
< span
319
330
style = { {
320
- color : ! isTestResult ( item )
321
- ? ""
322
- : ( item . passed ? "green" : "red" ) ,
331
+ color : ! isTestResult ( item ) ? "" : item . passed ? "green" : "red" ,
323
332
} }
324
333
>
325
334
Case { index + 1 }
@@ -335,21 +344,20 @@ export default function CollaborationPage(props: CollaborationProps) {
335
344
{ isTestResult ( item ) && (
336
345
< div className = "test-result-container" >
337
346
< InfoCircleFilled className = "hidden-test-icon" />
338
- < Typography . Text
339
- strong
347
+ < Typography . Text
348
+ strong
340
349
style = { { color : item . passed ? "green" : "red" } }
341
350
>
342
351
{ item . passed ? "Passed" : "Failed" }
343
352
</ Typography . Text >
344
353
< br />
345
- < Typography . Text strong > Actual Output:</ Typography . Text > { item . actual }
354
+ < Typography . Text strong > Actual Output:</ Typography . Text > { " " }
355
+ { item . actual }
346
356
< br />
347
357
{ item . error && (
348
358
< >
349
359
< Typography . Text strong > Error:</ Typography . Text >
350
- < div className = "error-message" >
351
- { item . error }
352
- </ div >
360
+ < div className = "error-message" > { item . error } </ div >
353
361
</ >
354
362
) }
355
363
</ div >
@@ -487,31 +495,50 @@ export default function CollaborationPage(props: CollaborationProps) {
487
495
) }
488
496
< div className = "hidden-test-results" >
489
497
< InfoCircleFilled className = "hidden-test-icon" />
490
- < Typography . Text
498
+ < Typography . Text
491
499
strong
492
500
style = { {
493
501
color : submissionHiddenTestResultsAndStatus
494
- ? submissionHiddenTestResultsAndStatus . status === "Accepted"
502
+ ? submissionHiddenTestResultsAndStatus . status ===
503
+ "Accepted"
495
504
? "green"
496
- : submissionHiddenTestResultsAndStatus . status === "Attempted"
505
+ : submissionHiddenTestResultsAndStatus . status ===
506
+ "Attempted"
497
507
? "orange"
498
508
: "black" // default color for any other status
499
509
: "gray" , // color for "Not Attempted"
500
510
} }
501
511
>
502
- Session Status: { submissionHiddenTestResultsAndStatus ? submissionHiddenTestResultsAndStatus . status : "Not Attempted" }
512
+ Session Status:{ " " }
513
+ { submissionHiddenTestResultsAndStatus
514
+ ? submissionHiddenTestResultsAndStatus . status
515
+ : "Not Attempted" }
503
516
</ Typography . Text >
504
517
< br />
505
518
{ submissionHiddenTestResultsAndStatus && (
506
519
< Typography . Text
507
520
strong
508
521
style = { {
509
- color : submissionHiddenTestResultsAndStatus . hiddenTestResults . passed === submissionHiddenTestResultsAndStatus . hiddenTestResults . total
510
- ? "green" // All test cases passed
511
- : "red" // Some test cases failed
522
+ color :
523
+ submissionHiddenTestResultsAndStatus . hiddenTestResults
524
+ . passed ===
525
+ submissionHiddenTestResultsAndStatus . hiddenTestResults
526
+ . total
527
+ ? "green" // All test cases passed
528
+ : "red" , // Some test cases failed
512
529
} }
513
530
>
514
- Passed { submissionHiddenTestResultsAndStatus . hiddenTestResults . passed } / { submissionHiddenTestResultsAndStatus . hiddenTestResults . total } hidden test cases
531
+ Passed{ " " }
532
+ {
533
+ submissionHiddenTestResultsAndStatus . hiddenTestResults
534
+ . passed
535
+ } { " " }
536
+ /{ " " }
537
+ {
538
+ submissionHiddenTestResultsAndStatus . hiddenTestResults
539
+ . total
540
+ } { " " }
541
+ hidden test cases
515
542
</ Typography . Text >
516
543
) }
517
544
</ div >
0 commit comments