@@ -75,7 +75,7 @@ const ContestSolutionSubmitPage = () => {
75
75
const { internalUser : user } = useAppSelector ( ( state ) => state . authorization ) ;
76
76
77
77
// Get the participationType type from route params or path (if not in params)
78
- const getParticipationType = ( ) => {
78
+ const getParticipationType = useCallback ( ( ) => {
79
79
if ( participationType ) {
80
80
return participationType === ContestParticipationType . Compete
81
81
? ContestParticipationType . Compete
@@ -85,7 +85,7 @@ const ContestSolutionSubmitPage = () => {
85
85
return location . pathname . includes ( `/${ ContestParticipationType . Compete } ` )
86
86
? ContestParticipationType . Compete
87
87
: ContestParticipationType . Practice ;
88
- } ;
88
+ } , [ participationType , location . pathname ] ) ;
89
89
90
90
const [ submitSolution , {
91
91
// isSuccess: submitSolutionSuccess,
@@ -111,7 +111,7 @@ const ContestSolutionSubmitPage = () => {
111
111
] = useLazyGetSubmissionResultsByProblemQuery ( ) ;
112
112
113
113
const isModalOpen = Boolean ( anchorEl ) ;
114
- const isCompete = getParticipationType ( ) === ContestParticipationType . Compete ;
114
+ const isCompete = useMemo ( ( ) => getParticipationType ( ) === ContestParticipationType . Compete , [ getParticipationType ] ) ;
115
115
116
116
const textColorClassName = getColorClassName ( themeColors . textColor ) ;
117
117
const lightBackgroundClassName = getColorClassName ( themeColors . baseColor100 ) ;
@@ -168,25 +168,26 @@ const ContestSolutionSubmitPage = () => {
168
168
useEffect ( ( ) => {
169
169
if ( submissionsData ?. items && problems && submissionsData . items . length > 0 ) {
170
170
// eslint-disable-next-line max-len
171
- const latestSubmission = submissionsData . items . reduce ( ( newest , current ) => new Date ( current . createdOn ) > new Date ( newest . createdOn )
171
+ const latestSubmission = submissionsData . items . reduce ( ( latest , current ) => new Date ( current . createdOn ) > new Date ( latest . createdOn )
172
172
? current
173
- : newest , submissionsData . items [ 0 ] ) ;
174
-
175
- if ( latestSubmission ? .problem ) {
176
- const problemIndex = problems . findIndex ( ( p ) => p . id === latestSubmission . problem . id ) ;
177
- if ( problemIndex !== - 1 ) {
178
- const updatedProblem = { ...problems [ problemIndex ] } ;
179
- updatedProblem . points = Math . max ( latestSubmission . result . points , updatedProblem . points ) ;
180
-
181
- setUpdatedProblems ( [
182
- ... problems . slice ( 0 , problemIndex ) ,
183
- updatedProblem ,
184
- ... problems . slice ( problemIndex + 1 ) ,
185
- ] ) ;
173
+ : latest ) ;
174
+
175
+ const updatedProblemIndex = problems . findIndex ( ( problem ) => problem . id === latestSubmission . problem . id ) ;
176
+
177
+ if ( updatedProblemIndex !== - 1 ) {
178
+ const newUpdatedProblems = [ ...problems ] ;
179
+ newUpdatedProblems [ updatedProblemIndex ] = {
180
+ ... problems [ updatedProblemIndex ] ,
181
+ points : Math . max ( latestSubmission . result . points , problems [ updatedProblemIndex ] . points ) ,
182
+ } ;
183
+
184
+ if ( JSON . stringify ( newUpdatedProblems ) !== JSON . stringify ( problems ) ) {
185
+ refetch ( ) ;
186
186
}
187
+ setUpdatedProblems ( newUpdatedProblems ) ;
187
188
}
188
189
}
189
- } , [ problems , submissionsData ] ) ;
190
+ } , [ submissionsData , problems , refetch ] ) ;
190
191
191
192
useEffect ( ( ) => {
192
193
if ( ! submissionsDataFetching ) {
0 commit comments