-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from scffs/marks-by-day
feat(marks-by-day): добавлены оценки на главную etc
- Loading branch information
Showing
16 changed files
with
276 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.marksByName { | ||
display: flex; | ||
margin-left: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { FC } from 'react'; | ||
import { | ||
Group, Header, HorizontalCell, HorizontalScroll, | ||
} from '@vkontakte/vkui'; | ||
|
||
import { Grade, PerformanceCurrent } from '../../../../../shared'; | ||
|
||
import Mark from '../Mark'; | ||
|
||
import './index.css'; | ||
|
||
interface IPerformanceCurrent { | ||
performanceData: PerformanceCurrent | null; | ||
} | ||
|
||
const truncateString = (str: string, maxLength: number) => { | ||
if (str.length > maxLength) { | ||
return `${str.substring(0, maxLength)}...`; | ||
} | ||
return str; | ||
}; | ||
|
||
const MarksByDay: FC<IPerformanceCurrent> = ({ performanceData }) => { | ||
const marksByDay: { [key: string]: { grades: Grade[]; lessonName: string } } = {}; | ||
|
||
performanceData?.daysWithMarksForSubject?.length !== undefined && performanceData?.daysWithMarksForSubject?.length > 0 && 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 (!marksByDay[day]) { | ||
marksByDay[day] = { grades: [], lessonName: '' }; | ||
} | ||
|
||
marksByDay[day].grades = [...marksByDay[day].grades, ...grades]; | ||
marksByDay[day].lessonName = lessonName; | ||
}); | ||
}); | ||
|
||
return ( | ||
<HorizontalScroll | ||
showArrows | ||
getScrollToLeft={(i) => i - 120} | ||
getScrollToRight={(i) => i + 120} | ||
> | ||
<Group header={<Header mode='secondary'>Недавние оценки</Header>}> | ||
<div className='marksByName'> | ||
{Object.entries(marksByDay).map(([day, { grades, lessonName }], index) => ( | ||
<div> | ||
<Header mode='secondary'>{day}</Header> | ||
<div key={index} style={{ display: 'flex' }}> | ||
{grades.map((grade, gradeIndex) => ( | ||
<HorizontalCell style={{ maxWidth: 'unset' }}> | ||
<Mark style={{ maxWidth: 90 }} key={gradeIndex} mark={grade} size='l' bottom={truncateString(lessonName, 18)} useMargin={false} /> | ||
</HorizontalCell> | ||
))} | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</Group> | ||
</HorizontalScroll> | ||
); | ||
}; | ||
|
||
export default MarksByDay; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import { IMark } from '../../../../shared'; | ||
|
||
import { getCookie } from '../bridge/getCookie'; | ||
import { getUserId } from '../bridge/getUserId'; | ||
|
||
// TODO: возможно придётся удалить | ||
export const getMarks = async (): Promise<IMark> => { | ||
const cookie = await getCookie(); | ||
const id = await getUserId(); | ||
|
||
const response = await fetch(`${import.meta.env.VITE_SERVER_URL}/dashboard/${id}`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json;charset=UTF-8', | ||
secret: cookie as string, | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error('Failed to fetch lessons'); | ||
} | ||
|
||
return await response.json() as IMark; | ||
}; | ||
// import { IMark } from '../../../../shared'; | ||
// | ||
// import { getCookie } from '../bridge/getCookie'; | ||
// import { getUserId } from '../bridge/getUserId'; | ||
// | ||
// // TODO: возможно придётся удалить | ||
// export const getMarks = async (): Promise<IMark> => { | ||
// const cookie = await getCookie(); | ||
// const id = await getUserId(); | ||
// | ||
// const response = await fetch(`${import.meta.env.VITE_SERVER_URL}/dashboard/${id}`, { | ||
// method: 'POST', | ||
// headers: { | ||
// 'Content-Type': 'application/json;charset=UTF-8', | ||
// secret: cookie as string, | ||
// }, | ||
// }); | ||
// | ||
// if (!response.ok) { | ||
// throw new Error('Failed to fetch lessons'); | ||
// } | ||
// | ||
// return await response.json() as IMark; | ||
// }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.