Skip to content

Commit

Permalink
fix: Fixes the saving pop-up to appear
Browse files Browse the repository at this point in the history
Moves the array updation statement and introduces two ways of updating
the grading statement.

Signed-off-by: Farhaan Bukhsh <[email protected]>
  • Loading branch information
farhaanbukhsh committed Oct 22, 2024
1 parent 3b56fab commit e7c5b7f
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions src/grading-settings/grading-scale/GradingScale.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,40 +55,44 @@ const GradingScale = ({
}, [gradingSegments, letters]);

const addNewGradingSegment = () => {
setGradingSegments(prevSegments => {
setGradingSegments((prevSegments) => {
let updatedGradingSegment = [];
if (prevSegments.length >= 5) {
const segSize = MAXIMUM_SCALE_LENGTH / (prevSegments.length + 1);
return Array.from({ length: prevSegments.length + 1 }).map((_, i) => (
{
current: 100 - i * segSize,
previous: 100 - (i + 1) * segSize,
}
));
}
const firstSegment = prevSegments[prevSegments.length - 1];
const secondSegment = prevSegments[prevSegments.length - 2];
const newCurrentValue = Math.ceil((secondSegment.current - secondSegment.previous) / 2);

const newSegment = {
current: (firstSegment.current + newCurrentValue),
previous: firstSegment.current,
};
updatedGradingSegment = Array.from({

Check warning on line 62 in src/grading-settings/grading-scale/GradingScale.jsx

View check run for this annotation

Codecov / codecov/patch

src/grading-settings/grading-scale/GradingScale.jsx#L62

Added line #L62 was not covered by tests
length: prevSegments.length + 1,
}).map((_, i) => ({

Check warning on line 64 in src/grading-settings/grading-scale/GradingScale.jsx

View check run for this annotation

Codecov / codecov/patch

src/grading-settings/grading-scale/GradingScale.jsx#L64

Added line #L64 was not covered by tests
current: 100 - i * segSize,
previous: 100 - (i + 1) * segSize,
}));
} else {
const firstSegment = prevSegments[prevSegments.length - 1];
const secondSegment = prevSegments[prevSegments.length - 2];
const newCurrentValue = Math.ceil(
(secondSegment.current - secondSegment.previous) / 2,
);

const newSegment = {
current: firstSegment.current + newCurrentValue,
previous: firstSegment.current,
};

const updatedSecondSegment = {
...secondSegment,
previous: (firstSegment.current + newCurrentValue),
};
const updatedSecondSegment = {
...secondSegment,
previous: firstSegment.current + newCurrentValue,
};
updatedGradingSegment = [
...prevSegments.slice(0, prevSegments.length - 2),
updatedSecondSegment,
newSegment,
firstSegment,
];
}

showSavePrompt(true);
setShowSuccessAlert(false);
setOverrideInternetConnectionAlert(false);

return [
...prevSegments.slice(0, prevSegments.length - 2),
updatedSecondSegment,
newSegment,
firstSegment,
];
return updatedGradingSegment;
});

const nextIndex = (letters.length % defaultGradeDesignations.length);
Expand Down

0 comments on commit e7c5b7f

Please sign in to comment.