Skip to content

Commit 12323f8

Browse files
authored
The problems' points are now updated properly. Fixed an issue where the component would re-render every time the page was clicked on. (#1297)
Closes SoftUni-Internal/exam-systems-issues#1410
1 parent 41e63b7 commit 12323f8

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

Servers/UI/OJS.Servers.Ui/ClientApp/src/components/submissions/execution-result/TestRunIcon.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const TestRunIcon = ({ testRun }: ITestRunIconProps) => {
3737

3838
const renderTestRunIcon = useCallback(
3939
() => {
40-
console.log(iconClassName);
4140
switch (toLowerCase(testRun.resultType)) {
4241
// TODO: https://github.com/SoftUni-Internal/exam-systems-issues/issues/1287
4342
case TestRunResultType.CorrectAnswer.toLowerCase(): return <TickIcon className={iconClassName} key={testRun.id} />;

Servers/UI/OJS.Servers.Ui/ClientApp/src/pages/contests/contest-solution-submit/ContestSolutionSubmitPage.tsx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const ContestSolutionSubmitPage = () => {
7575
const { internalUser: user } = useAppSelector((state) => state.authorization);
7676

7777
// Get the participationType type from route params or path (if not in params)
78-
const getParticipationType = () => {
78+
const getParticipationType = useCallback(() => {
7979
if (participationType) {
8080
return participationType === ContestParticipationType.Compete
8181
? ContestParticipationType.Compete
@@ -85,7 +85,7 @@ const ContestSolutionSubmitPage = () => {
8585
return location.pathname.includes(`/${ContestParticipationType.Compete}`)
8686
? ContestParticipationType.Compete
8787
: ContestParticipationType.Practice;
88-
};
88+
}, [ participationType, location.pathname ]);
8989

9090
const [ submitSolution, {
9191
// isSuccess: submitSolutionSuccess,
@@ -111,7 +111,7 @@ const ContestSolutionSubmitPage = () => {
111111
] = useLazyGetSubmissionResultsByProblemQuery();
112112

113113
const isModalOpen = Boolean(anchorEl);
114-
const isCompete = getParticipationType() === ContestParticipationType.Compete;
114+
const isCompete = useMemo(() => getParticipationType() === ContestParticipationType.Compete, [ getParticipationType ]);
115115

116116
const textColorClassName = getColorClassName(themeColors.textColor);
117117
const lightBackgroundClassName = getColorClassName(themeColors.baseColor100);
@@ -168,25 +168,26 @@ const ContestSolutionSubmitPage = () => {
168168
useEffect(() => {
169169
if (submissionsData?.items && problems && submissionsData.items.length > 0) {
170170
// 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)
172172
? 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();
186186
}
187+
setUpdatedProblems(newUpdatedProblems);
187188
}
188189
}
189-
}, [ problems, submissionsData ]);
190+
}, [ submissionsData, problems, refetch ]);
190191

191192
useEffect(() => {
192193
if (!submissionsDataFetching) {

0 commit comments

Comments
 (0)