@@ -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 handleRunTestCases = async ( ) => {
@@ -239,7 +243,7 @@ export default function CollaborationPage(props: CollaborationProps) {
239
243
language : selectedLanguage ,
240
244
customTestCases : "" ,
241
245
} ) ;
242
- setVisibleTestCases ( data . visibleTestResults ) ;
246
+ updateExecutionResults ( data ) ;
243
247
infoMessage ( "Test cases executed. Review the results below." ) ;
244
248
sendExecutionResultsToMatchedUser ( data ) ;
245
249
setIsLoadingTestCase ( false ) ;
@@ -262,11 +266,11 @@ export default function CollaborationPage(props: CollaborationProps) {
262
266
questionDifficulty : complexity ?? "" ,
263
267
questionTopics : categories ,
264
268
} ) ;
265
- setVisibleTestCases ( data . visibleTestResults ) ;
266
- setSubmissionHiddenTestResultsAndStatus ( {
267
- hiddenTestResults : data . hiddenTestResults ,
268
- status : data . status ,
269
+ updateExecutionResults ( {
270
+ visibleTestResults : data . visibleTestResults ,
271
+ customTestResults : [ ] ,
269
272
} ) ;
273
+ updateSubmissionResults ( data ) ;
270
274
sendSubmissionResultsToMatchedUser ( data ) ;
271
275
successMessage ( "Code saved successfully!" ) ;
272
276
setIsLoadingSubmission ( false ) ;
@@ -291,13 +295,20 @@ export default function CollaborationPage(props: CollaborationProps) {
291
295
const currentUser : string = localStorage . getItem ( "user" ) ?? "" ;
292
296
const matchedTopics : string [ ] =
293
297
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" ) ?? "[]" ) ?? [ ] ;
294
303
295
304
// Set states from localstorage
296
305
setCollaborationId ( collabId ) ;
297
306
setMatchedUser ( matchedUser ) ;
298
307
setCurrentUser ( currentUser ) ;
299
308
setMatchedTopics ( matchedTopics ) ;
300
309
setQuestionDocRefId ( questionDocRefId ) ;
310
+ setSubmissionHiddenTestResultsAndStatus ( submissionHiddenTestResultsAndStatus ) ;
311
+ setVisibleTestCases ( visibleTestCases ) ;
301
312
302
313
GetSingleQuestion ( questionDocRefId ) . then ( ( data : Question ) => {
303
314
setQuestionTitle ( `${ data . id } . ${ data . title } ` ) ;
@@ -306,13 +317,13 @@ export default function CollaborationPage(props: CollaborationProps) {
306
317
setDescription ( data . description ) ;
307
318
} ) ;
308
319
309
- GetVisibleTests ( questionDocRefId )
310
- . then ( ( data : Test [ ] ) => {
320
+ if ( visibleTestCases . length == 0 ) {
321
+ GetVisibleTests ( questionDocRefId ) . then ( ( data : Test [ ] ) => {
311
322
setVisibleTestCases ( data ) ;
312
- } )
313
- . catch ( ( e ) => {
323
+ } ) . catch ( ( e ) => {
314
324
errorMessage ( e . message ) ;
315
325
} ) ;
326
+ }
316
327
317
328
// Start stopwatch
318
329
startStopwatch ( ) ;
@@ -396,6 +407,8 @@ export default function CollaborationPage(props: CollaborationProps) {
396
407
localStorage . removeItem ( "collabId" ) ;
397
408
localStorage . removeItem ( "questionDocRefId" ) ;
398
409
localStorage . removeItem ( "matchedTopics" ) ;
410
+ localStorage . removeItem ( "submissionHiddenTestResultsAndStatus" ) ;
411
+ localStorage . removeItem ( "visibleTestResults" ) ;
399
412
localStorage . removeItem ( "editor-language" ) ; // Remove editor language type when session closed
400
413
} ;
401
414
0 commit comments