@@ -71,7 +71,7 @@ export default function CollaborationPage(props: CollaborationProps) {
7171 const [ complexity , setComplexity ] = useState < string | undefined > ( undefined ) ;
7272 const [ categories , setCategories ] = useState < string [ ] > ( [ ] ) ; // Store the selected filter categories
7373 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
7575
7676 // Session states
7777 const [ collaborationId , setCollaborationId ] = useState < string | undefined > (
@@ -232,22 +232,29 @@ export default function CollaborationPage(props: CollaborationProps) {
232232 localStorage . setItem ( "visibleTestResults" , JSON . stringify ( data . visibleTestResults ) ) ;
233233 } ;
234234
235+ const updateLangauge = ( data : string ) => {
236+ setSelectedLanguage ( data ) ;
237+ }
238+
235239 const handleRunTestCases = async ( ) => {
236240 if ( ! questionDocRefId ) {
237241 throw new Error ( "Question ID not found" ) ;
238242 }
239243 setIsLoadingTestCase ( true ) ;
240244 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+ }
251258 } ;
252259
253260 const handleSubmitCode = async ( ) => {
@@ -256,25 +263,28 @@ export default function CollaborationPage(props: CollaborationProps) {
256263 }
257264 setIsLoadingSubmission ( true ) ;
258265 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+ }
278288 } ;
279289
280290 const handleCodeChange = ( code : string ) => {
@@ -505,7 +515,7 @@ export default function CollaborationPage(props: CollaborationProps) {
505515 ref = { editorRef }
506516 user = { currentUser }
507517 collaborationId = { collaborationId }
508- language = { selectedLanguage }
518+ updateLanguage = { updateLangauge }
509519 setMatchedUser = { setMatchedUser }
510520 handleCloseCollaboration = { handleCloseCollaboration }
511521 providerRef = { providerRef }
0 commit comments