@@ -71,7 +71,7 @@ export default function CollaborationPage(props: CollaborationProps) {
71
71
const [ complexity , setComplexity ] = useState < string | undefined > ( undefined ) ;
72
72
const [ categories , setCategories ] = useState < string [ ] > ( [ ] ) ; // Store the selected filter categories
73
73
const [ description , setDescription ] = useState < string | undefined > ( undefined ) ;
74
- const [ selectedLanguage , setSelectedLanguage ] = useState ( "Python " ) ; // State to hold the selected language item
74
+ const [ selectedLanguage , setSelectedLanguage ] = useState ( "python " ) ; // State to hold the selected language item
75
75
76
76
// Session states
77
77
const [ collaborationId , setCollaborationId ] = useState < string | undefined > (
@@ -228,22 +228,29 @@ export default function CollaborationPage(props: CollaborationProps) {
228
228
setVisibleTestCases ( data . visibleTestResults ) ;
229
229
} ;
230
230
231
+ const updateLangauge = ( data : string ) => {
232
+ setSelectedLanguage ( data ) ;
233
+ }
234
+
231
235
const handleRunTestCases = async ( ) => {
232
236
if ( ! questionDocRefId ) {
233
237
throw new Error ( "Question ID not found" ) ;
234
238
}
235
239
setIsLoadingTestCase ( true ) ;
236
240
sendExecutingStateToMatchedUser ( true ) ;
237
- const data = await ExecuteVisibleAndCustomTests ( questionDocRefId , {
238
- code : code ,
239
- language : selectedLanguage ,
240
- customTestCases : "" ,
241
- } ) ;
242
- setVisibleTestCases ( data . visibleTestResults ) ;
243
- infoMessage ( "Test cases executed. Review the results below." ) ;
244
- sendExecutionResultsToMatchedUser ( data ) ;
245
- setIsLoadingTestCase ( false ) ;
246
- sendExecutingStateToMatchedUser ( false ) ;
241
+ try {
242
+ const data = await ExecuteVisibleAndCustomTests ( questionDocRefId , {
243
+ code : code ,
244
+ language : selectedLanguage ,
245
+ customTestCases : "" ,
246
+ } ) ;
247
+ setVisibleTestCases ( data . visibleTestResults ) ;
248
+ infoMessage ( "Test cases executed. Review the results below." ) ;
249
+ sendExecutionResultsToMatchedUser ( data ) ;
250
+ } finally {
251
+ setIsLoadingTestCase ( false ) ;
252
+ sendExecutingStateToMatchedUser ( false ) ;
253
+ }
247
254
} ;
248
255
249
256
const handleSubmitCode = async ( ) => {
@@ -252,25 +259,28 @@ export default function CollaborationPage(props: CollaborationProps) {
252
259
}
253
260
setIsLoadingSubmission ( true ) ;
254
261
sendSubmittingStateToMatchedUser ( true ) ;
255
- const data = await ExecuteVisibleAndHiddenTestsAndSubmit ( questionDocRefId , {
256
- code : code ,
257
- language : selectedLanguage ,
258
- user : currentUser ?? "" ,
259
- matchedUser : matchedUser ?? "" ,
260
- matchedTopics : matchedTopics ?? [ ] ,
261
- title : questionTitle ?? "" ,
262
- questionDifficulty : complexity ?? "" ,
263
- questionTopics : categories ,
264
- } ) ;
265
- setVisibleTestCases ( data . visibleTestResults ) ;
266
- setSubmissionHiddenTestResultsAndStatus ( {
267
- hiddenTestResults : data . hiddenTestResults ,
268
- status : data . status ,
269
- } ) ;
270
- sendSubmissionResultsToMatchedUser ( data ) ;
271
- successMessage ( "Code saved successfully!" ) ;
272
- setIsLoadingSubmission ( false ) ;
273
- sendSubmittingStateToMatchedUser ( false ) ;
262
+ try {
263
+ const data = await ExecuteVisibleAndHiddenTestsAndSubmit ( questionDocRefId , {
264
+ code : code ,
265
+ language : selectedLanguage ,
266
+ user : currentUser ?? "" ,
267
+ matchedUser : matchedUser ?? "" ,
268
+ matchedTopics : matchedTopics ?? [ ] ,
269
+ title : questionTitle ?? "" ,
270
+ questionDifficulty : complexity ?? "" ,
271
+ questionTopics : categories ,
272
+ } ) ;
273
+ setVisibleTestCases ( data . visibleTestResults ) ;
274
+ setSubmissionHiddenTestResultsAndStatus ( {
275
+ hiddenTestResults : data . hiddenTestResults ,
276
+ status : data . status ,
277
+ } ) ;
278
+ sendSubmissionResultsToMatchedUser ( data ) ;
279
+ successMessage ( "Code saved successfully!" ) ;
280
+ } finally {
281
+ setIsLoadingSubmission ( false ) ;
282
+ sendSubmittingStateToMatchedUser ( false ) ;
283
+ }
274
284
} ;
275
285
276
286
const handleCodeChange = ( code : string ) => {
@@ -492,7 +502,7 @@ export default function CollaborationPage(props: CollaborationProps) {
492
502
ref = { editorRef }
493
503
user = { currentUser }
494
504
collaborationId = { collaborationId }
495
- language = { selectedLanguage }
505
+ updateLanguage = { updateLangauge }
496
506
setMatchedUser = { setMatchedUser }
497
507
handleCloseCollaboration = { handleCloseCollaboration }
498
508
providerRef = { providerRef }
0 commit comments