@@ -209,15 +209,19 @@ export default function CollaborationPage(props: CollaborationProps) {
209209 } ;
210210
211211 const updateSubmissionResults = ( data : SubmissionResults ) => {
212- setSubmissionHiddenTestResultsAndStatus ( {
212+ const submissionHiddenTestResultsAndStatus : SubmissionHiddenTestResultsAndStatus = {
213213 hiddenTestResults : data . hiddenTestResults ,
214214 status : data . status ,
215- } ) ;
215+ }
216+ setSubmissionHiddenTestResultsAndStatus ( submissionHiddenTestResultsAndStatus ) ;
217+ localStorage . setItem ( "submissionHiddenTestResultsAndStatus" , JSON . stringify ( submissionHiddenTestResultsAndStatus ) ) ;
216218 setVisibleTestCases ( data . visibleTestResults ) ;
219+ localStorage . setItem ( "visibleTestResults" , JSON . stringify ( data . visibleTestResults ) ) ;
217220 } ;
218221
219222 const updateExecutionResults = ( data : ExecutionResults ) => {
220223 setVisibleTestCases ( data . visibleTestResults ) ;
224+ localStorage . setItem ( "visibleTestResults" , JSON . stringify ( data . visibleTestResults ) ) ;
221225 } ;
222226
223227 const handleRunTestCases = async ( ) => {
@@ -231,7 +235,7 @@ export default function CollaborationPage(props: CollaborationProps) {
231235 language : selectedLanguage ,
232236 customTestCases : "" ,
233237 } ) ;
234- setVisibleTestCases ( data . visibleTestResults ) ;
238+ updateExecutionResults ( data ) ;
235239 infoMessage ( "Test cases executed. Review the results below." ) ;
236240 sendExecutionResultsToMatchedUser ( data ) ;
237241 setIsLoadingTestCase ( false ) ;
@@ -254,11 +258,11 @@ export default function CollaborationPage(props: CollaborationProps) {
254258 questionDifficulty : complexity ?? "" ,
255259 questionTopics : categories ,
256260 } ) ;
257- setVisibleTestCases ( data . visibleTestResults ) ;
258- setSubmissionHiddenTestResultsAndStatus ( {
259- hiddenTestResults : data . hiddenTestResults ,
260- status : data . status ,
261+ updateExecutionResults ( {
262+ visibleTestResults : data . visibleTestResults ,
263+ customTestResults : [ ] ,
261264 } ) ;
265+ updateSubmissionResults ( data ) ;
262266 sendSubmissionResultsToMatchedUser ( data ) ;
263267 successMessage ( "Code saved successfully!" ) ;
264268 setIsLoadingSubmission ( false ) ;
@@ -283,13 +287,20 @@ export default function CollaborationPage(props: CollaborationProps) {
283287 const currentUser : string = localStorage . getItem ( "user" ) ?? "" ;
284288 const matchedTopics : string [ ] =
285289 localStorage . getItem ( "matchedTopics" ) ?. split ( "," ) ?? [ ] ;
290+ const submissionHiddenTestResultsAndStatus : SubmissionHiddenTestResultsAndStatus | undefined =
291+ localStorage . getItem ( "submissionHiddenTestResultsAndStatus" )
292+ ? JSON . parse ( localStorage . getItem ( "submissionHiddenTestResultsAndStatus" ) as string )
293+ : undefined ;
294+ const visibleTestCases : Test [ ] = JSON . parse ( localStorage . getItem ( "visibleTestResults" ) ?? "[]" ) ?? [ ] ;
286295
287296 // Set states from localstorage
288297 setCollaborationId ( collabId ) ;
289298 setMatchedUser ( matchedUser ) ;
290299 setCurrentUser ( currentUser ) ;
291300 setMatchedTopics ( matchedTopics ) ;
292301 setQuestionDocRefId ( questionDocRefId ) ;
302+ setSubmissionHiddenTestResultsAndStatus ( submissionHiddenTestResultsAndStatus ) ;
303+ setVisibleTestCases ( visibleTestCases ) ;
293304
294305 GetSingleQuestion ( questionDocRefId ) . then ( ( data : Question ) => {
295306 setQuestionTitle ( `${ data . id } . ${ data . title } ` ) ;
@@ -298,9 +309,11 @@ export default function CollaborationPage(props: CollaborationProps) {
298309 setDescription ( data . description ) ;
299310 } ) ;
300311
301- GetVisibleTests ( questionDocRefId ) . then ( ( data : Test [ ] ) => {
302- setVisibleTestCases ( data ) ;
303- } ) ;
312+ if ( visibleTestCases . length == 0 ) {
313+ GetVisibleTests ( questionDocRefId ) . then ( ( data : Test [ ] ) => {
314+ setVisibleTestCases ( data ) ;
315+ } ) ;
316+ }
304317
305318 // Start stopwatch
306319 startStopwatch ( ) ;
@@ -384,6 +397,8 @@ export default function CollaborationPage(props: CollaborationProps) {
384397 localStorage . removeItem ( "collabId" ) ;
385398 localStorage . removeItem ( "questionDocRefId" ) ;
386399 localStorage . removeItem ( "matchedTopics" ) ;
400+ localStorage . removeItem ( "submissionHiddenTestResultsAndStatus" ) ;
401+ localStorage . removeItem ( "visibleTestResults" ) ;
387402 } ;
388403
389404 return (
0 commit comments