Skip to content

Commit

Permalink
fix incorrect lesson's name
Browse files Browse the repository at this point in the history
  • Loading branch information
scffs committed Sep 12, 2023
1 parent 002f4f8 commit 13d2d4d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 37 deletions.
55 changes: 27 additions & 28 deletions frontend/src/components/UI/MarksByDay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from 'react';
import React, { FC } from 'react';
import {
Group, Header, HorizontalCell, HorizontalScroll,
} from '@vkontakte/vkui';
Expand All @@ -19,11 +19,11 @@ const truncateString = (str: string, maxLength: number) => {
}
return str;
};

interface IMarksByDay {
[key: string] : {
grades: Grade[];
lessonName: string
}
[key: string]: {
[lessonName: string]: Grade[];
};
}

const MarksByDay: FC<IPerformanceCurrent> = ({ performanceData }) => {
Expand All @@ -37,29 +37,17 @@ const MarksByDay: FC<IPerformanceCurrent> = ({ performanceData }) => {

if (grades.length > 0 && grades.every((grade) => !Number.isNaN(parseFloat(grade as string)))) {
if (!marksByDay[day]) {
marksByDay[day] = { grades: [], lessonName: '' };
marksByDay[day] = {};
}

if (!marksByDay[day][lessonName]) {
marksByDay[day][lessonName] = [];
}

marksByDay[day].grades = [...marksByDay[day].grades, ...grades];
marksByDay[day].lessonName = lessonName;
marksByDay[day][lessonName] = [...marksByDay[day][lessonName], ...grades];
}
});
});

const sort_by_day = (marksByDay: IMarksByDay): IMarksByDay => {
const mass = Object.keys(marksByDay).sort((b, a) => new Date(a).getTime() - new Date(b).getTime());
const marksByDaySort: IMarksByDay = {};

mass.forEach((day) => {
if (!marksByDaySort[day]) {
marksByDaySort[day] = { grades: [], lessonName: '' };
}

marksByDaySort[day].grades = [...marksByDay[day].grades];
marksByDaySort[day].lessonName = marksByDay[day].lessonName;
})
return marksByDaySort;
}

return (
<HorizontalScroll
Expand All @@ -69,14 +57,25 @@ const MarksByDay: FC<IPerformanceCurrent> = ({ performanceData }) => {
>
<Group header={<Header mode='secondary'>Недавние оценки</Header>}>
<div className='marksByName'>
{Object.entries(sort_by_day(marksByDay)).map(([day, { grades, lessonName }]) => (
{Object.entries(marksByDay).map(([day, lessonGrades]) => (
<div key={day}>
<Header mode='secondary'>{day}</Header>
<div style={{ display: 'flex' }}>
{grades.map((grade, gradeIndex) => (
<HorizontalCell style={{ maxWidth: 'unset' }} key={`${day}_${gradeIndex}`}>
<Mark style={{ maxWidth: 90 }} mark={grade || 'Н'} size='l' bottom={truncateString(lessonName, 18)} useMargin={false} />
</HorizontalCell>
{Object.entries(lessonGrades).map(([lessonName, grades]) => (
<React.Fragment key={`${day}_${lessonName}`}>
{grades.map((grade, gradeIndex) => (
<HorizontalCell style={{ maxWidth: 'unset' }} key={`${day}_${lessonName}_${gradeIndex}`}>
<Mark
style={{ maxWidth: 90 }}
key={`${day}_${lessonName}_${gradeIndex}`}
mark={grade || 'Н'}
size='l'
bottom={truncateString(lessonName, 18)}
useMargin={false}
/>
</HorizontalCell>
))}
</React.Fragment>
))}
</div>
</div>
Expand Down
40 changes: 31 additions & 9 deletions frontend/src/views/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Notifications: FC<{ id: string }> = ({ id }) => {
try {
if (isHandle) {
const ads = await getAds();
console.log('asd', ads)
console.log('asd', ads);
handleResponse(
ads,
() => {
Expand All @@ -52,7 +52,7 @@ const Notifications: FC<{ id: string }> = ({ id }) => {
},
showSnackbar,
);

updateCache(ads as NotificationsResponse[]);
setAdsData(ads as NotificationsResponse[]);
} else {
Expand All @@ -76,7 +76,7 @@ const Notifications: FC<{ id: string }> = ({ id }) => {

useEffect(() => {
const cachedAds = localStorage.getItem('savedAds');
console.log(cachedAds)
console.log(cachedAds);
if (cachedAds) {
setAdsData(JSON.parse(cachedAds));
showSnackbar({
Expand Down Expand Up @@ -105,8 +105,30 @@ const Notifications: FC<{ id: string }> = ({ id }) => {
}) => (
<Group
key={id}
description={(<div style={{ display: 'flex', gap: 10 }}>{isForEmployees && <SubtitleWithBorder>Для работников</SubtitleWithBorder>}{isForParents && <SubtitleWithBorder color='yellow-outline'>Для родителей</SubtitleWithBorder>}{isForStudents && <SubtitleWithBorder color='green-outline'>Для студентов</SubtitleWithBorder>}</div>)}
header={(<Header mode='tertiary' aside={(<Subhead>Удалится через{' '}{deleteInDays}{' '}дней</Subhead>)}>{new Date(date).toLocaleDateString()}</Header>)}>
description={(
<div style={{ display: 'flex', gap: 10 }}>
{isForEmployees && <SubtitleWithBorder>Для работников</SubtitleWithBorder>}
{isForParents && <SubtitleWithBorder color='yellow-outline'>Для родителей</SubtitleWithBorder>}
{isForStudents && <SubtitleWithBorder color='green-outline'>Для студентов</SubtitleWithBorder>}
</div>
)}
header={(
<Header
mode='tertiary'
aside={(
<Subhead>
Удалится через
{' '}
{deleteInDays}
{' '}
дней
</Subhead>
)}
>
{new Date(date).toLocaleDateString()}
</Header>
)}
>
<Card mode='shadow'>
<Div>
<Title level='3'>{title}</Title>
Expand All @@ -116,15 +138,15 @@ const Notifications: FC<{ id: string }> = ({ id }) => {
</Group>
))
)}

<Div>
{isLoading && (
<Div>
<Spinner />
</Div>
)}
</Div>

<Div>
{isError
&& (
Expand All @@ -141,9 +163,9 @@ const Notifications: FC<{ id: string }> = ({ id }) => {
/>
)}
</Div>

<Div>
{adsData && adsData?.length < 1 && <Placeholder header='Объявлений нет' />}
{adsData && adsData?.length < 1 && <Placeholder header='Объявлений нет' />}
</Div>
{snackbar}
</Div>
Expand Down

0 comments on commit 13d2d4d

Please sign in to comment.