@@ -22,16 +22,22 @@ import {
22
22
ClockCircleOutlined ,
23
23
CodeOutlined ,
24
24
InfoCircleFilled ,
25
- MessageOutlined ,
26
25
SendOutlined ,
27
26
VideoCameraOutlined ,
28
27
} from "@ant-design/icons" ;
29
28
import CollaborativeEditor , {
30
29
CollaborativeEditorHandle ,
31
30
} from "@/components/CollaborativeEditor/CollaborativeEditor" ;
32
- import { CreateHistory } from "@/app/services/history" ;
33
31
import { WebrtcProvider } from "y-webrtc" ;
34
- import { ExecuteVisibleAndCustomTests , ExecuteVisibleAndHiddenTestsAndSubmit , ExecutionResults , GetVisibleTests , isTestResult , SubmissionHiddenTestResultsAndStatus , SubmissionResults , Test , TestData , TestResult } from "@/app/services/execute" ;
32
+ import {
33
+ ExecuteVisibleAndCustomTests ,
34
+ ExecuteVisibleAndHiddenTestsAndSubmit ,
35
+ ExecutionResults ,
36
+ GetVisibleTests ,
37
+ SubmissionHiddenTestResultsAndStatus ,
38
+ SubmissionResults ,
39
+ Test ,
40
+ } from "@/app/services/execute" ;
35
41
import { QuestionDetailFull } from "@/components/question/QuestionDetailFull/QuestionDetailFull" ;
36
42
import VideoPanel from "@/components/VideoPanel/VideoPanel" ;
37
43
@@ -89,8 +95,12 @@ export default function CollaborationPage(props: CollaborationProps) {
89
95
) ;
90
96
const [ visibleTestCases , setVisibleTestCases ] = useState < Test [ ] > ( [ ] ) ;
91
97
const [ isLoadingTestCase , setIsLoadingTestCase ] = useState < boolean > ( false ) ;
92
- const [ isLoadingSubmission , setIsLoadingSubmission ] = useState < boolean > ( false ) ;
93
- const [ submissionHiddenTestResultsAndStatus , setSubmissionHiddenTestResultsAndStatus ] = useState < SubmissionHiddenTestResultsAndStatus | undefined > ( undefined ) ;
98
+ const [ isLoadingSubmission , setIsLoadingSubmission ] =
99
+ useState < boolean > ( false ) ;
100
+ const [
101
+ submissionHiddenTestResultsAndStatus ,
102
+ setSubmissionHiddenTestResultsAndStatus ,
103
+ ] = useState < SubmissionHiddenTestResultsAndStatus | undefined > ( undefined ) ;
94
104
95
105
// End Button Modal state
96
106
const [ isModalOpen , setIsModalOpen ] = useState < boolean > ( false ) ;
@@ -151,7 +161,7 @@ export default function CollaborationPage(props: CollaborationProps) {
151
161
type : "info" ,
152
162
content : message ,
153
163
} ) ;
154
- }
164
+ } ;
155
165
156
166
const sendSubmissionResultsToMatchedUser = ( data : SubmissionResults ) => {
157
167
if ( ! providerRef . current ) {
@@ -161,7 +171,7 @@ export default function CollaborationPage(props: CollaborationProps) {
161
171
submissionResults : data ,
162
172
id : Date . now ( ) ,
163
173
} ) ;
164
- }
174
+ } ;
165
175
166
176
const sendExecutingStateToMatchedUser = ( executing : boolean ) => {
167
177
if ( ! providerRef . current ) {
@@ -171,7 +181,7 @@ export default function CollaborationPage(props: CollaborationProps) {
171
181
executing : executing ,
172
182
id : Date . now ( ) ,
173
183
} ) ;
174
- }
184
+ } ;
175
185
176
186
const sendSubmittingStateToMatchedUser = ( submitting : boolean ) => {
177
187
if ( ! providerRef . current ) {
@@ -181,7 +191,7 @@ export default function CollaborationPage(props: CollaborationProps) {
181
191
submitting : submitting ,
182
192
id : Date . now ( ) ,
183
193
} ) ;
184
- }
194
+ } ;
185
195
186
196
const sendExecutionResultsToMatchedUser = ( data : ExecutionResults ) => {
187
197
if ( ! providerRef . current ) {
@@ -191,60 +201,54 @@ export default function CollaborationPage(props: CollaborationProps) {
191
201
executionResults : data ,
192
202
id : Date . now ( ) ,
193
203
} ) ;
194
- }
204
+ } ;
195
205
196
206
const updateSubmissionResults = ( data : SubmissionResults ) => {
197
207
setSubmissionHiddenTestResultsAndStatus ( {
198
208
hiddenTestResults : data . hiddenTestResults ,
199
209
status : data . status ,
200
210
} ) ;
201
211
setVisibleTestCases ( data . visibleTestResults ) ;
202
- }
212
+ } ;
203
213
204
214
const updateExecutionResults = ( data : ExecutionResults ) => {
205
215
setVisibleTestCases ( data . visibleTestResults ) ;
206
- }
216
+ } ;
207
217
208
218
const handleRunTestCases = async ( ) => {
209
219
if ( ! questionDocRefId ) {
210
220
throw new Error ( "Question ID not found" ) ;
211
221
}
212
222
setIsLoadingTestCase ( true ) ;
213
223
sendExecutingStateToMatchedUser ( true ) ;
214
- const data = await ExecuteVisibleAndCustomTests (
215
- questionDocRefId ,
216
- {
217
- code : code ,
218
- language : selectedLanguage ,
219
- customTestCases : "" ,
220
- }
221
- ) ;
224
+ const data = await ExecuteVisibleAndCustomTests ( questionDocRefId , {
225
+ code : code ,
226
+ language : selectedLanguage ,
227
+ customTestCases : "" ,
228
+ } ) ;
222
229
setVisibleTestCases ( data . visibleTestResults ) ;
223
- infoMessage ( "Test cases executed. Review the results below." )
230
+ infoMessage ( "Test cases executed. Review the results below." ) ;
224
231
sendExecutionResultsToMatchedUser ( data ) ;
225
232
setIsLoadingTestCase ( false ) ;
226
233
sendExecutingStateToMatchedUser ( false ) ;
227
- }
234
+ } ;
228
235
229
236
const handleSubmitCode = async ( ) => {
230
237
if ( ! questionDocRefId ) {
231
238
throw new Error ( "Question ID not found" ) ;
232
239
}
233
240
setIsLoadingSubmission ( true ) ;
234
241
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
- ) ;
242
+ const data = await ExecuteVisibleAndHiddenTestsAndSubmit ( questionDocRefId , {
243
+ code : code ,
244
+ language : selectedLanguage ,
245
+ user : currentUser ?? "" ,
246
+ matchedUser : matchedUser ?? "" ,
247
+ matchedTopics : matchedTopics ?? [ ] ,
248
+ title : questionTitle ?? "" ,
249
+ questionDifficulty : complexity ?? "" ,
250
+ questionTopics : categories ,
251
+ } ) ;
248
252
setVisibleTestCases ( data . visibleTestResults ) ;
249
253
setSubmissionHiddenTestResultsAndStatus ( {
250
254
hiddenTestResults : data . hiddenTestResults ,
@@ -254,7 +258,7 @@ export default function CollaborationPage(props: CollaborationProps) {
254
258
successMessage ( "Code saved successfully!" ) ;
255
259
setIsLoadingSubmission ( false ) ;
256
260
sendSubmittingStateToMatchedUser ( false ) ;
257
- }
261
+ } ;
258
262
259
263
const handleCodeChange = ( code : string ) => {
260
264
setCode ( code ) ;
@@ -310,55 +314,6 @@ export default function CollaborationPage(props: CollaborationProps) {
310
314
}
311
315
} , [ isSessionEndModalOpen , countDown ] ) ;
312
316
313
- // Tabs component items for visibleTestCases
314
- var items : TabsProps [ "items" ] = visibleTestCases . map ( ( item , index ) => {
315
- return {
316
- key : index . toString ( ) ,
317
- label : (
318
- < span
319
- style = { {
320
- color : ! isTestResult ( item )
321
- ? ""
322
- : ( item . passed ? "green" : "red" ) ,
323
- } }
324
- >
325
- Case { index + 1 }
326
- </ span >
327
- ) ,
328
- children : (
329
- < div >
330
- < Input . TextArea
331
- disabled
332
- placeholder = { `Stdin: ${ item . input } \nStdout: ${ item . expected } ` }
333
- rows = { 4 }
334
- />
335
- { isTestResult ( item ) && (
336
- < div className = "test-result-container" >
337
- < InfoCircleFilled className = "hidden-test-icon" />
338
- < Typography . Text
339
- strong
340
- style = { { color : item . passed ? "green" : "red" } }
341
- >
342
- { item . passed ? "Passed" : "Failed" }
343
- </ Typography . Text >
344
- < br />
345
- < Typography . Text strong > Actual Output:</ Typography . Text > { item . actual }
346
- < br />
347
- { item . error && (
348
- < >
349
- < Typography . Text strong > Error:</ Typography . Text >
350
- < div className = "error-message" >
351
- { item . error }
352
- </ div >
353
- </ >
354
- ) }
355
- </ div >
356
- ) }
357
- </ div >
358
- ) ,
359
- } ;
360
- } ) ;
361
-
362
317
// Handles the cleaning of localstorage variables, stopping the timer & signalling collab user on webrtc
363
318
// type: "initiator" | "peer"
364
319
const handleCloseCollaboration = ( type : string ) => {
@@ -438,7 +393,7 @@ export default function CollaborationPage(props: CollaborationProps) {
438
393
complexity = { complexity }
439
394
categories = { categories }
440
395
description = { description }
441
- testcaseItems = { items }
396
+ visibleTestcases = { visibleTestCases }
442
397
shouldShowSubmitButton
443
398
handleRunTestCases = { handleRunTestCases }
444
399
isLoadingTestCase = { isLoadingTestCase }
@@ -487,31 +442,50 @@ export default function CollaborationPage(props: CollaborationProps) {
487
442
) }
488
443
< div className = "hidden-test-results" >
489
444
< InfoCircleFilled className = "hidden-test-icon" />
490
- < Typography . Text
445
+ < Typography . Text
491
446
strong
492
447
style = { {
493
448
color : submissionHiddenTestResultsAndStatus
494
- ? submissionHiddenTestResultsAndStatus . status === "Accepted"
449
+ ? submissionHiddenTestResultsAndStatus . status ===
450
+ "Accepted"
495
451
? "green"
496
- : submissionHiddenTestResultsAndStatus . status === "Attempted"
452
+ : submissionHiddenTestResultsAndStatus . status ===
453
+ "Attempted"
497
454
? "orange"
498
455
: "black" // default color for any other status
499
456
: "gray" , // color for "Not Attempted"
500
457
} }
501
458
>
502
- Session Status: { submissionHiddenTestResultsAndStatus ? submissionHiddenTestResultsAndStatus . status : "Not Attempted" }
459
+ Session Status:{ " " }
460
+ { submissionHiddenTestResultsAndStatus
461
+ ? submissionHiddenTestResultsAndStatus . status
462
+ : "Not Attempted" }
503
463
</ Typography . Text >
504
464
< br />
505
465
{ submissionHiddenTestResultsAndStatus && (
506
466
< Typography . Text
507
467
strong
508
468
style = { {
509
- color : submissionHiddenTestResultsAndStatus . hiddenTestResults . passed === submissionHiddenTestResultsAndStatus . hiddenTestResults . total
510
- ? "green" // All test cases passed
511
- : "red" // Some test cases failed
469
+ color :
470
+ submissionHiddenTestResultsAndStatus . hiddenTestResults
471
+ . passed ===
472
+ submissionHiddenTestResultsAndStatus . hiddenTestResults
473
+ . total
474
+ ? "green" // All test cases passed
475
+ : "red" , // Some test cases failed
512
476
} }
513
477
>
514
- Passed { submissionHiddenTestResultsAndStatus . hiddenTestResults . passed } / { submissionHiddenTestResultsAndStatus . hiddenTestResults . total } hidden test cases
478
+ Passed{ " " }
479
+ {
480
+ submissionHiddenTestResultsAndStatus . hiddenTestResults
481
+ . passed
482
+ } { " " }
483
+ /{ " " }
484
+ {
485
+ submissionHiddenTestResultsAndStatus . hiddenTestResults
486
+ . total
487
+ } { " " }
488
+ hidden test cases
515
489
</ Typography . Text >
516
490
) }
517
491
</ div >
0 commit comments