Skip to content

Commit

Permalink
Updates: ready to 2 semester (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
scffs authored Jan 8, 2024
1 parent 7297ea0 commit 6331a89
Show file tree
Hide file tree
Showing 21 changed files with 619 additions and 380 deletions.
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"]
}
}
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
"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",
"@preact/preset-vite": "^2.8.1",
"@rollup/plugin-terser": "^0.4.4",
"@types/node": "^20.9.1",
"@vitest/coverage-v8": "^0.34.6",
"@types/node": "^20.10.7",
"@vitest/coverage-v8": "^1.1.3",
"@vkontakte/vk-miniapps-deploy": "^0.1.6",
"gh-pages": "^6.0.0",
"jsdom": "^22.1.0",
"jsdom": "^23.2.0",
"typescript": "^5.2.2",
"vite": "^5.0.5",
"vitest": "^0.34.6",
"vite": "^5.0.11",
"vitest": "^1.1.3",
"vitest-localstorage-mock": "^0.0.1"
}
}
7 changes: 4 additions & 3 deletions src/AppWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import {
usePlatform
} from '@vkontakte/vkui'
import { lazy } from 'preact/compat'
import AuthProvider from './AuthProvider.tsx'
import { router } from './routes'
import { transformVKBridgeAdaptivity } from './transformers/transformVKBridgeAdaptivity'

const App = lazy(() => import('./App'))
const NotFoundCorrect = lazy(() => import('./views/NotFound'))

vkBridge.send('VKWebAppInit')

const AppWrapper = () => {
const platform = usePlatform()
const vkBridgeAdaptivityProps = transformVKBridgeAdaptivity(useAdaptivity())
Expand All @@ -30,7 +29,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
23 changes: 23 additions & 0 deletions src/components/TechWorking.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// import { AppRoot, Button, Div } from '@vkontakte/vkui'
// import { notFoundStyle, text } from '../views/NotFound.tsx'
//
// const TechWorking = () => {
// return (
// <AppRoot style={{ overflow: 'hidden' }}>
// <Div style={notFoundStyle}>
// <h1 style={text}>Тех. работы</h1>
// <Button
// onClick={() => window.open('https://poo.tomedu.ru')}
// size='l'
// mode='outline'
// appearance='accent-invariable'
// style={{ padding: 10 }}
// >
// <span style={{ fontSize: '1.5em' }}>poo.tomedu.ru</span>
// </Button>
// </Div>
// </AppRoot>
// )
// }
//
// export default TechWorking
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
5 changes: 4 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Suspense } from '@components'
import '@vkontakte/vkui/dist/vkui.css'
import { render } from 'preact'
import AppWrapper from './AppWrapper'

import vkBridge from '@vkontakte/vk-bridge'
import AppWrapper from './AppWrapper.tsx'
import './index.css'

vkBridge.send('VKWebAppInit')

render(
<Suspense id='AppWrapper' mode='screen'>
<AppWrapper />
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
}
Loading

0 comments on commit 6331a89

Please sign in to comment.