@@ -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 > (
@@ -232,22 +232,29 @@ export default function CollaborationPage(props: CollaborationProps) {
232
232
localStorage . setItem ( "visibleTestResults" , JSON . stringify ( data . visibleTestResults ) ) ;
233
233
} ;
234
234
235
+ const updateLangauge = ( data : string ) => {
236
+ setSelectedLanguage ( data ) ;
237
+ }
238
+
235
239
const handleRunTestCases = async ( ) => {
236
240
if ( ! questionDocRefId ) {
237
241
throw new Error ( "Question ID not found" ) ;
238
242
}
239
243
setIsLoadingTestCase ( true ) ;
240
244
sendExecutingStateToMatchedUser ( true ) ;
241
- const data = await ExecuteVisibleAndCustomTests ( questionDocRefId , {
242
- code : code ,
243
- language : selectedLanguage ,
244
- customTestCases : "" ,
245
- } ) ;
246
- updateExecutionResults ( data ) ;
247
- infoMessage ( "Test cases executed. Review the results below." ) ;
248
- sendExecutionResultsToMatchedUser ( data ) ;
249
- setIsLoadingTestCase ( false ) ;
250
- sendExecutingStateToMatchedUser ( false ) ;
245
+ try {
246
+ const data = await ExecuteVisibleAndCustomTests ( questionDocRefId , {
247
+ code : code ,
248
+ language : selectedLanguage ,
249
+ customTestCases : "" ,
250
+ } ) ;
251
+ updateExecutionResults ( data ) ;
252
+ infoMessage ( "Test cases executed. Review the results below." ) ;
253
+ sendExecutionResultsToMatchedUser ( data ) ;
254
+ } finally {
255
+ setIsLoadingTestCase ( false ) ;
256
+ sendExecutingStateToMatchedUser ( false ) ;
257
+ }
251
258
} ;
252
259
253
260
const handleSubmitCode = async ( ) => {
@@ -256,25 +263,28 @@ export default function CollaborationPage(props: CollaborationProps) {
256
263
}
257
264
setIsLoadingSubmission ( true ) ;
258
265
sendSubmittingStateToMatchedUser ( true ) ;
259
- const data = await ExecuteVisibleAndHiddenTestsAndSubmit ( questionDocRefId , {
260
- code : code ,
261
- language : selectedLanguage ,
262
- user : currentUser ?? "" ,
263
- matchedUser : matchedUser ?? "" ,
264
- matchedTopics : matchedTopics ?? [ ] ,
265
- title : questionTitle ?? "" ,
266
- questionDifficulty : complexity ?? "" ,
267
- questionTopics : categories ,
268
- } ) ;
269
- updateExecutionResults ( {
270
- visibleTestResults : data . visibleTestResults ,
271
- customTestResults : [ ] ,
272
- } ) ;
273
- updateSubmissionResults ( data ) ;
274
- sendSubmissionResultsToMatchedUser ( data ) ;
275
- successMessage ( "Code saved successfully!" ) ;
276
- setIsLoadingSubmission ( false ) ;
277
- sendSubmittingStateToMatchedUser ( false ) ;
266
+ try {
267
+ const data = await ExecuteVisibleAndHiddenTestsAndSubmit ( questionDocRefId , {
268
+ code : code ,
269
+ language : selectedLanguage ,
270
+ user : currentUser ?? "" ,
271
+ matchedUser : matchedUser ?? "" ,
272
+ matchedTopics : matchedTopics ?? [ ] ,
273
+ title : questionTitle ?? "" ,
274
+ questionDifficulty : complexity ?? "" ,
275
+ questionTopics : categories ,
276
+ } ) ;
277
+ updateExecutionResults ( {
278
+ visibleTestResults : data . visibleTestResults ,
279
+ customTestResults : [ ] ,
280
+ } ) ;
281
+ updateSubmissionResults ( data ) ;
282
+ sendSubmissionResultsToMatchedUser ( data ) ;
283
+ successMessage ( "Code saved successfully!" ) ;
284
+ } finally {
285
+ setIsLoadingSubmission ( false ) ;
286
+ sendSubmittingStateToMatchedUser ( false ) ;
287
+ }
278
288
} ;
279
289
280
290
const handleCodeChange = ( code : string ) => {
@@ -505,7 +515,7 @@ export default function CollaborationPage(props: CollaborationProps) {
505
515
ref = { editorRef }
506
516
user = { currentUser }
507
517
collaborationId = { collaborationId }
508
- language = { selectedLanguage }
518
+ updateLanguage = { updateLangauge }
509
519
setMatchedUser = { setMatchedUser }
510
520
handleCloseCollaboration = { handleCloseCollaboration }
511
521
providerRef = { providerRef }
0 commit comments