Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates: ready to 2 semester #97

Merged
merged 7 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"formatter": {
"indentStyle": "space",
"indentWidth": 2,
"ignore": ["node_modules"]
"ignore": ["node_modules", "yarn.lock", "coverage"]
},
"javascript": {
"formatter": {
Expand All @@ -19,8 +19,11 @@
"linter": {
"enabled": true,
"rules": {
"recommended": true
"recommended": true,
"suspicious": {
"noArrayIndexKey": "off"
}
},
"ignore": ["node_modules", "bun.lockb"]
"ignore": ["node_modules", "yarn.lock", "coverage"]
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"devDependencies": {
"@babel/eslint-parser": "^7.23.3",
"@biomejs/biome": "1.4.1",
"@diary-spo/shared": "^1.8.5",
"@diary-spo/shared": "^1.8.6",
"@diary-spo/types": "latest",
"@preact/preset-vite": "^2.7.0",
"@rollup/plugin-terser": "^0.4.4",
Expand Down
5 changes: 4 additions & 1 deletion src/AppWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
usePlatform
} from '@vkontakte/vkui'
import { lazy } from 'preact/compat'
import AuthProvider from './AuthProvider.tsx'
import { router } from './routes'
import { transformVKBridgeAdaptivity } from './transformers/transformVKBridgeAdaptivity'

Expand All @@ -30,7 +31,9 @@ const AppWrapper = () => {
platform={platform}
isWebView={vkBridge.isWebView()}
>
<App />
<AuthProvider>
<App />
</AuthProvider>
</ConfigProvider>
</Suspense>
</RouterProvider>
Expand Down
19 changes: 7 additions & 12 deletions src/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,28 @@ import {
useActiveVkuiLocation,
useRouteNavigator
} from '@vkontakte/vk-mini-apps-router'
import { ReactNode } from 'preact/compat'
import { useEffect } from 'preact/hooks'
import {
MAIN_SETTINGS,
VIEW_SCHEDULE,
} from './routes'
import { VNode } from 'preact'
import { useLayoutEffect } from 'react'
import { MAIN_SETTINGS, VIEW_SCHEDULE } from './routes'

const AuthProvider = ({ children }: {children: ReactNode}) => {
const AuthProvider = ({ children }: { children: VNode }) => {
const routeNavigator = useRouteNavigator()
const { view: activeView, panel } = useActiveVkuiLocation()


const cookieValue = localStorage.getItem('token')

useEffect(() => {
useLayoutEffect(() => {
const onRoute = () => {
if (!cookieValue) {
routeNavigator.replace('/')
} else if (cookieValue && panel === MAIN_SETTINGS) {
routeNavigator.replace(`/${VIEW_SCHEDULE}`)
}

}

onRoute()
}, [activeView, window.location])
}, [activeView, panel])

return children
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/UI/Marks/MarksByGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import {
import { FC } from 'preact/compat'
import AverageMarkCell from './AverageMarkCell'
import MarksList from './MarksList'
import NoData from './NoData'

interface IMarksByGroup {
marksForSubject: PerformanceCurrent | null
}

const MarksByGroup: FC<IMarksByGroup> = ({ marksForSubject }) => {
if (!marksForSubject) {
return <NoData />
console.log(marksForSubject)
if (!marksForSubject?.daysWithMarksForSubject.length) {
return
}

const subjectMarksMap = createSubjectMarksMap(marksForSubject)
Expand Down
24 changes: 0 additions & 24 deletions src/components/UI/Marks/NoData.tsx

This file was deleted.

82 changes: 50 additions & 32 deletions src/components/UI/Summary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Icon20EducationOutline, Icon28BrainOutline } from '@vkontakte/icons'
import { Group, Header, MiniInfoCell } from '@vkontakte/vkui'
import { FC } from 'preact/compat'
import React from 'preact/compat'
import Mark from './Mark'

interface ISummary {
Expand All @@ -14,39 +15,56 @@ const Summary: FC<ISummary> = ({
totalNumberOfMarks,
averageMark
}) => (
<Group header={<Header mode='tertiary'>Статистика</Header>}>
<MiniInfoCell
before={<Icon20EducationOutline style={{ marginTop: 4 }} />}
after={<Mark size='s' mark={totalNumberOfMarks} />}
>
Суммарное количество оценок:
</MiniInfoCell>
<MiniInfoCell
before={
<Icon28BrainOutline style={{ marginTop: 4 }} width={20} height={20} />
}
after={<Mark size='s' mark={averageMark} />}
>
Общий средний балл:
</MiniInfoCell>
{markCounts && (
<div
style={{
display: 'flex',
flexDirection: 'row-reverse',
justifyContent: 'space-around',
gap: 5
}}
>
{[2, 3, 4, 5].map(
(mark) =>
markCounts[mark] > 0 && (
<MiniInfoCell key={mark} before={<Mark mark={mark} size='s' />}>
x {markCounts[mark]}
</MiniInfoCell>
)
<Group
header={
<Header mode='tertiary'>
Статистика {!markCounts && 'отсутствует'}{' '}
</Header>
}
>
{!markCounts ? undefined : (
<React.Fragment>
<MiniInfoCell
before={<Icon20EducationOutline style={{ marginTop: 4 }} />}
after={<Mark size='s' mark={totalNumberOfMarks} />}
>
Суммарное количество оценок:
</MiniInfoCell>
<MiniInfoCell
before={
<Icon28BrainOutline
style={{ marginTop: 4 }}
width={20}
height={20}
/>
}
after={<Mark size='s' mark={averageMark} />}
>
Общий средний балл:
</MiniInfoCell>
{markCounts && (
<div
style={{
display: 'flex',
flexDirection: 'row-reverse',
justifyContent: 'space-around',
gap: 5
}}
>
{[2, 3, 4, 5].map(
(mark) =>
markCounts[mark] > 0 && (
<MiniInfoCell
key={mark}
before={<Mark mark={mark} size='s' />}
>
x {markCounts[mark]}
</MiniInfoCell>
)
)}
</div>
)}
</div>
</React.Fragment>
)}
</Group>
)
Expand Down
2 changes: 1 addition & 1 deletion src/methods/server/requestToSecondServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const requestToSecondServer = async <T>(
}

if (!secondServerResponse.ok) {
throw new Error(`Failed to fetch data from ${route} and SECOND_SERVER`)
return secondServerResponse.status
}

return (await secondServerResponse.json()) as T
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export interface Storage {
value: string
}

export type ServerResponse<T = unknown> = Promise<T | 418 | 429 | 401>
export type ServerResponse<T = unknown> = Promise<T | 418 | 429 | 401 | number>

export const loginPattern = /^[a-zA-Z0-9а-яА-ЯёЁ-]+$/
10 changes: 5 additions & 5 deletions src/utils/formatted/formatStatisticsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export const formatStatisticsData = (marks: PerformanceCurrent) => {
const allMarks: TextMark[] = marks.daysWithMarksForSubject.reduce(
(marksArray: TextMark[], subject) => {
if (subject.daysWithMarks) {
subject.daysWithMarks.forEach((day) =>
for (const day of subject.daysWithMarks) {
// @ts-ignore
marksArray.push(...day.markValues)
)
}
}
return marksArray
},
Expand All @@ -39,12 +39,12 @@ export const formatStatisticsData = (marks: PerformanceCurrent) => {
5: 0
}

allMarks.forEach((textMark: TextMark) => {
const numericMark: number = Grade[textMark] as number
for (const textMark of allMarks) {
const numericMark = Number(Grade[textMark])
if (numericMark >= 2 && numericMark <= 5) {
markCounts[numericMark] += 1
}
})
}

return {
totalNumberOfMarks,
Expand Down
13 changes: 8 additions & 5 deletions src/utils/marks/calculateAverageMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ export const calculateAverageMark = (
let sum = 0
let validMarksCount = 0

marks.forEach((mark) => {
for (const mark of marks) {
const markNumber = Number(Grade[mark])
if (!Number.isNaN(markNumber)) {
sum += markNumber
validMarksCount++

if (Number.isNaN(markNumber)) {
continue
}
})

sum += markNumber
validMarksCount++
}

if (validMarksCount === 0) {
return null
Expand Down
18 changes: 10 additions & 8 deletions src/utils/marks/createSubjectMarksMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,25 @@ export const createSubjectMarksMap = (
): SubjectMarksMap => {
const subjectMarksMap: SubjectMarksMap = {}

marksForSubject.daysWithMarksForSubject.forEach((subject) => {
for (const subject of marksForSubject.daysWithMarksForSubject) {
const { subjectName, daysWithMarks } = subject

if (!subjectMarksMap[subjectName]) {
subjectMarksMap[subjectName] = []
}

if (daysWithMarks) {
const mappedMarks = daysWithMarks.map((dayWithMark) => ({
date: new Date(dayWithMark.day).toLocaleDateString(),
marks: dayWithMark.markValues,
absenceType: dayWithMark.absenceType
}))
for (const dayWithMark of daysWithMarks) {
const mappedMarks = {
date: new Date(dayWithMark.day).toLocaleDateString(),
marks: dayWithMark.markValues,
absenceType: dayWithMark.absenceType
}

subjectMarksMap[subjectName].push(...mappedMarks)
subjectMarksMap[subjectName].push(mappedMarks)
}
}
})
}

return subjectMarksMap
}
18 changes: 6 additions & 12 deletions src/utils/marks/extractMarksByDay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ export const extractMarksByDay = (
performanceData: PerformanceCurrent | null
): IMarksByDay => {
const marksByDay: IMarksByDay = {}

performanceData?.daysWithMarksForSubject?.forEach((subject) => {
subject?.daysWithMarks?.forEach((markData) => {
for (const subject of performanceData?.daysWithMarksForSubject || []) {
for (const markData of subject?.daysWithMarks || []) {
const day = new Date(markData.day).toLocaleDateString()
const lessonName = subject.subjectName

Expand All @@ -24,20 +23,15 @@ export const extractMarksByDay = (
const grades = validGrades.map((gradeText) => Number(Grade[gradeText]))

if (grades.length > 0) {
if (!marksByDay[day]) {
marksByDay[day] = {}
}

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

if (grades.every((grade) => !Number.isNaN(grade))) {
marksByDay[day][lessonName].push(...grades)
}
}
})
})
}
}

return marksByDay
}
5 changes: 3 additions & 2 deletions src/utils/sortByDay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ export const sortByDay = (marksByDay: IMarksByDay): IMarksByDay => {
const sortedDays = Object.keys(marksByDay).sort(
(a, b) => formatDate(b).getTime() - formatDate(a).getTime()
)

const marksByDaySort: IMarksByDay = {}
sortedDays.forEach((day) => {
for (const day of sortedDays) {
marksByDaySort[day] = marksByDay[day]
})
}

return marksByDaySort
}
Loading
Loading