@@ -217,15 +217,19 @@ export default function CollaborationPage(props: CollaborationProps) {
217
217
} ;
218
218
219
219
const updateSubmissionResults = ( data : SubmissionResults ) => {
220
- setSubmissionHiddenTestResultsAndStatus ( {
220
+ const submissionHiddenTestResultsAndStatus : SubmissionHiddenTestResultsAndStatus = {
221
221
hiddenTestResults : data . hiddenTestResults ,
222
222
status : data . status ,
223
- } ) ;
223
+ }
224
+ setSubmissionHiddenTestResultsAndStatus ( submissionHiddenTestResultsAndStatus ) ;
225
+ localStorage . setItem ( "submissionHiddenTestResultsAndStatus" , JSON . stringify ( submissionHiddenTestResultsAndStatus ) ) ;
224
226
setVisibleTestCases ( data . visibleTestResults ) ;
227
+ localStorage . setItem ( "visibleTestResults" , JSON . stringify ( data . visibleTestResults ) ) ;
225
228
} ;
226
229
227
230
const updateExecutionResults = ( data : ExecutionResults ) => {
228
231
setVisibleTestCases ( data . visibleTestResults ) ;
232
+ localStorage . setItem ( "visibleTestResults" , JSON . stringify ( data . visibleTestResults ) ) ;
229
233
} ;
230
234
231
235
const updateLangauge = ( data : string ) => {
@@ -244,7 +248,7 @@ export default function CollaborationPage(props: CollaborationProps) {
244
248
language : selectedLanguage ,
245
249
customTestCases : "" ,
246
250
} ) ;
247
- setVisibleTestCases ( data . visibleTestResults ) ;
251
+ updateExecutionResults ( data ) ;
248
252
infoMessage ( "Test cases executed. Review the results below." ) ;
249
253
sendExecutionResultsToMatchedUser ( data ) ;
250
254
} finally {
@@ -270,11 +274,11 @@ export default function CollaborationPage(props: CollaborationProps) {
270
274
questionDifficulty : complexity ?? "" ,
271
275
questionTopics : categories ,
272
276
} ) ;
273
- setVisibleTestCases ( data . visibleTestResults ) ;
274
- setSubmissionHiddenTestResultsAndStatus ( {
275
- hiddenTestResults : data . hiddenTestResults ,
276
- status : data . status ,
277
+ updateExecutionResults ( {
278
+ visibleTestResults : data . visibleTestResults ,
279
+ customTestResults : [ ] ,
277
280
} ) ;
281
+ updateSubmissionResults ( data ) ;
278
282
sendSubmissionResultsToMatchedUser ( data ) ;
279
283
successMessage ( "Code saved successfully!" ) ;
280
284
} finally {
@@ -301,13 +305,20 @@ export default function CollaborationPage(props: CollaborationProps) {
301
305
const currentUser : string = localStorage . getItem ( "user" ) ?? "" ;
302
306
const matchedTopics : string [ ] =
303
307
localStorage . getItem ( "matchedTopics" ) ?. split ( "," ) ?? [ ] ;
308
+ const submissionHiddenTestResultsAndStatus : SubmissionHiddenTestResultsAndStatus | undefined =
309
+ localStorage . getItem ( "submissionHiddenTestResultsAndStatus" )
310
+ ? JSON . parse ( localStorage . getItem ( "submissionHiddenTestResultsAndStatus" ) as string )
311
+ : undefined ;
312
+ const visibleTestCases : Test [ ] = JSON . parse ( localStorage . getItem ( "visibleTestResults" ) ?? "[]" ) ?? [ ] ;
304
313
305
314
// Set states from localstorage
306
315
setCollaborationId ( collabId ) ;
307
316
setMatchedUser ( matchedUser ) ;
308
317
setCurrentUser ( currentUser ) ;
309
318
setMatchedTopics ( matchedTopics ) ;
310
319
setQuestionDocRefId ( questionDocRefId ) ;
320
+ setSubmissionHiddenTestResultsAndStatus ( submissionHiddenTestResultsAndStatus ) ;
321
+ setVisibleTestCases ( visibleTestCases ) ;
311
322
312
323
GetSingleQuestion ( questionDocRefId ) . then ( ( data : Question ) => {
313
324
setQuestionTitle ( `${ data . id } . ${ data . title } ` ) ;
@@ -316,13 +327,13 @@ export default function CollaborationPage(props: CollaborationProps) {
316
327
setDescription ( data . description ) ;
317
328
} ) ;
318
329
319
- GetVisibleTests ( questionDocRefId )
320
- . then ( ( data : Test [ ] ) => {
330
+ if ( visibleTestCases . length == 0 ) {
331
+ GetVisibleTests ( questionDocRefId ) . then ( ( data : Test [ ] ) => {
321
332
setVisibleTestCases ( data ) ;
322
- } )
323
- . catch ( ( e ) => {
333
+ } ) . catch ( ( e ) => {
324
334
errorMessage ( e . message ) ;
325
335
} ) ;
336
+ }
326
337
327
338
// Start stopwatch
328
339
startStopwatch ( ) ;
@@ -406,6 +417,8 @@ export default function CollaborationPage(props: CollaborationProps) {
406
417
localStorage . removeItem ( "collabId" ) ;
407
418
localStorage . removeItem ( "questionDocRefId" ) ;
408
419
localStorage . removeItem ( "matchedTopics" ) ;
420
+ localStorage . removeItem ( "submissionHiddenTestResultsAndStatus" ) ;
421
+ localStorage . removeItem ( "visibleTestResults" ) ;
409
422
localStorage . removeItem ( "editor-language" ) ; // Remove editor language type when session closed
410
423
} ;
411
424
0 commit comments