@@ -217,15 +217,19 @@ export default function CollaborationPage(props: CollaborationProps) {
217217 } ;
218218
219219 const updateSubmissionResults = ( data : SubmissionResults ) => {
220- setSubmissionHiddenTestResultsAndStatus ( {
220+ const submissionHiddenTestResultsAndStatus : SubmissionHiddenTestResultsAndStatus = {
221221 hiddenTestResults : data . hiddenTestResults ,
222222 status : data . status ,
223- } ) ;
223+ }
224+ setSubmissionHiddenTestResultsAndStatus ( submissionHiddenTestResultsAndStatus ) ;
225+ localStorage . setItem ( "submissionHiddenTestResultsAndStatus" , JSON . stringify ( submissionHiddenTestResultsAndStatus ) ) ;
224226 setVisibleTestCases ( data . visibleTestResults ) ;
227+ localStorage . setItem ( "visibleTestResults" , JSON . stringify ( data . visibleTestResults ) ) ;
225228 } ;
226229
227230 const updateExecutionResults = ( data : ExecutionResults ) => {
228231 setVisibleTestCases ( data . visibleTestResults ) ;
232+ localStorage . setItem ( "visibleTestResults" , JSON . stringify ( data . visibleTestResults ) ) ;
229233 } ;
230234
231235 const handleRunTestCases = async ( ) => {
@@ -239,7 +243,7 @@ export default function CollaborationPage(props: CollaborationProps) {
239243 language : selectedLanguage ,
240244 customTestCases : "" ,
241245 } ) ;
242- setVisibleTestCases ( data . visibleTestResults ) ;
246+ updateExecutionResults ( data ) ;
243247 infoMessage ( "Test cases executed. Review the results below." ) ;
244248 sendExecutionResultsToMatchedUser ( data ) ;
245249 setIsLoadingTestCase ( false ) ;
@@ -262,11 +266,11 @@ export default function CollaborationPage(props: CollaborationProps) {
262266 questionDifficulty : complexity ?? "" ,
263267 questionTopics : categories ,
264268 } ) ;
265- setVisibleTestCases ( data . visibleTestResults ) ;
266- setSubmissionHiddenTestResultsAndStatus ( {
267- hiddenTestResults : data . hiddenTestResults ,
268- status : data . status ,
269+ updateExecutionResults ( {
270+ visibleTestResults : data . visibleTestResults ,
271+ customTestResults : [ ] ,
269272 } ) ;
273+ updateSubmissionResults ( data ) ;
270274 sendSubmissionResultsToMatchedUser ( data ) ;
271275 successMessage ( "Code saved successfully!" ) ;
272276 setIsLoadingSubmission ( false ) ;
@@ -291,13 +295,20 @@ export default function CollaborationPage(props: CollaborationProps) {
291295 const currentUser : string = localStorage . getItem ( "user" ) ?? "" ;
292296 const matchedTopics : string [ ] =
293297 localStorage . getItem ( "matchedTopics" ) ?. split ( "," ) ?? [ ] ;
298+ const submissionHiddenTestResultsAndStatus : SubmissionHiddenTestResultsAndStatus | undefined =
299+ localStorage . getItem ( "submissionHiddenTestResultsAndStatus" )
300+ ? JSON . parse ( localStorage . getItem ( "submissionHiddenTestResultsAndStatus" ) as string )
301+ : undefined ;
302+ const visibleTestCases : Test [ ] = JSON . parse ( localStorage . getItem ( "visibleTestResults" ) ?? "[]" ) ?? [ ] ;
294303
295304 // Set states from localstorage
296305 setCollaborationId ( collabId ) ;
297306 setMatchedUser ( matchedUser ) ;
298307 setCurrentUser ( currentUser ) ;
299308 setMatchedTopics ( matchedTopics ) ;
300309 setQuestionDocRefId ( questionDocRefId ) ;
310+ setSubmissionHiddenTestResultsAndStatus ( submissionHiddenTestResultsAndStatus ) ;
311+ setVisibleTestCases ( visibleTestCases ) ;
301312
302313 GetSingleQuestion ( questionDocRefId ) . then ( ( data : Question ) => {
303314 setQuestionTitle ( `${ data . id } . ${ data . title } ` ) ;
@@ -306,13 +317,13 @@ export default function CollaborationPage(props: CollaborationProps) {
306317 setDescription ( data . description ) ;
307318 } ) ;
308319
309- GetVisibleTests ( questionDocRefId )
310- . then ( ( data : Test [ ] ) => {
320+ if ( visibleTestCases . length == 0 ) {
321+ GetVisibleTests ( questionDocRefId ) . then ( ( data : Test [ ] ) => {
311322 setVisibleTestCases ( data ) ;
312- } )
313- . catch ( ( e ) => {
323+ } ) . catch ( ( e ) => {
314324 errorMessage ( e . message ) ;
315325 } ) ;
326+ }
316327
317328 // Start stopwatch
318329 startStopwatch ( ) ;
@@ -396,6 +407,8 @@ export default function CollaborationPage(props: CollaborationProps) {
396407 localStorage . removeItem ( "collabId" ) ;
397408 localStorage . removeItem ( "questionDocRefId" ) ;
398409 localStorage . removeItem ( "matchedTopics" ) ;
410+ localStorage . removeItem ( "submissionHiddenTestResultsAndStatus" ) ;
411+ localStorage . removeItem ( "visibleTestResults" ) ;
399412 localStorage . removeItem ( "editor-language" ) ; // Remove editor language type when session closed
400413 } ;
401414
0 commit comments