From ebcd97d857793324f508ebb4d3b892e366ace8c6 Mon Sep 17 00:00:00 2001 From: Semyon Okulov Date: Tue, 12 Sep 2023 12:56:28 +0700 Subject: [PATCH] fix incorrect lesson's order --- frontend/src/components/UI/MarksByDay/index.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/UI/MarksByDay/index.tsx b/frontend/src/components/UI/MarksByDay/index.tsx index 71193db1..42effef5 100644 --- a/frontend/src/components/UI/MarksByDay/index.tsx +++ b/frontend/src/components/UI/MarksByDay/index.tsx @@ -28,27 +28,29 @@ interface IMarksByDay { const MarksByDay: FC = ({ performanceData }) => { const marksByDay: IMarksByDay = {}; - + performanceData?.daysWithMarksForSubject?.forEach((subject) => { subject?.daysWithMarks?.forEach((dayWithMarks) => { const day = new Date(dayWithMarks.day).toLocaleDateString(); const grades = dayWithMarks.markValues.map((gradeText) => Grade[gradeText]); const lessonName = subject.subjectName; - + if (grades.length > 0 && grades.every((grade) => !Number.isNaN(parseFloat(grade as string)))) { if (!marksByDay[day]) { marksByDay[day] = {}; } - + if (!marksByDay[day][lessonName]) { marksByDay[day][lessonName] = []; } - + marksByDay[day][lessonName] = [...marksByDay[day][lessonName], ...grades]; } }); }); - + + const sortedDates = Object.keys(marksByDay).sort((a, b) => new Date(b).getTime() - new Date(a).getTime()); + return ( = ({ performanceData }) => { > Недавние оценки}>
- {Object.entries(marksByDay).map(([day, lessonGrades]) => ( + {sortedDates.map((day) => (
{day}
- {Object.entries(lessonGrades).map(([lessonName, grades]) => ( + {Object.entries(marksByDay[day]).map(([lessonName, grades]) => ( {grades.map((grade, gradeIndex) => (