Skip to content

Commit

Permalink
move shared to other package
Browse files Browse the repository at this point in the history
  • Loading branch information
scffs committed Sep 12, 2023
1 parent ebcd97d commit c59f033
Show file tree
Hide file tree
Showing 27 changed files with 73 additions and 338 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@vitejs/plugin-basic-ssl": "^1.0.1",
"@vitejs/plugin-react-swc": "^3.3.2",
"@vkontakte/vk-miniapps-deploy": "^0.1.6",
"diary-shared": "^1.6.2",
"eslint": "^8.45.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.1.0",
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/LessonCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
} from '@vkontakte/vkui';
import { useRouteNavigator } from '@vkontakte/vk-mini-apps-router';
import {
Day, EAbsenceTypes, Grade, Gradebook, LessonWorkType, Timetable,
} from '../../../shared';
Day, EAbsenceTypes, Gradebook, LessonWorkType, Timetable,
} from '/diary-shared';
import { formatLessonDate, getDayOfWeek } from '../utils/formatLessonDate';
import setDefaultMark from '../utils/setDefaultMark';
import { isToday } from '../utils/isToday';
Expand All @@ -14,6 +14,7 @@ import { useModal } from '../modals/ModalContext';
import SubtitleWithBorder from './SubtitleWithBorder';
import TimeRemaining from './TimeRemaining';
import Mark from './UI/Mark';
import {Grade} from "../types";

interface ILessonCard {
lesson: Day;
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/MarksByGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import {
Icon28InfoCircle,
} from '@vkontakte/icons';
import {
AbsenceType, EAbsenceTypes, Grade, PerformanceCurrent, TextMark,
} from '../../../shared';
AbsenceType, EAbsenceTypes, PerformanceCurrent, TextMark,
} from '/diary-shared';
import { getPerformance } from '../methods';
import calculateAverageMark from '../utils/calculateAverageMark';
import { useSnackbar } from '../hooks';
import Mark from './UI/Mark';
import { handleResponse } from '../utils/handleResponse';
import {Grade} from "../types";

const THIRD_SEC = 30 * 1000;

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ScheduleGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FC } from 'react';
// TODO: Сделать переключатель для расписания
import { CardGrid } from '@vkontakte/vkui';
import { Day } from '../../../shared';
import { Day } from 'diary-shared';
import LessonCard from './LessonCard';

interface IScheduleGroup {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/UI/Mark/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CSSProperties, FC } from 'react';
import { Footnote } from '@vkontakte/vkui';
import { EAbsenceTypes, TMark } from '../../../../../shared';
import { EAbsenceTypes } from 'diary-shared';
import { TMark } from '../../../../../shared';

type Sizes = 'l' | 's';

Expand Down
18 changes: 8 additions & 10 deletions frontend/src/components/UI/MarksByDay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import React, { FC } from 'react';
import {
Group, Header, HorizontalCell, HorizontalScroll,
} from '@vkontakte/vkui';

import { Grade, PerformanceCurrent } from '../../../../../shared';

import { PerformanceCurrent } from 'diary-shared';
import Mark from '../Mark';

import {Grade} from "../../../types";
import './index.css';

interface IPerformanceCurrent {
Expand All @@ -28,29 +26,29 @@ interface IMarksByDay {

const MarksByDay: FC<IPerformanceCurrent> = ({ 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 (
<HorizontalScroll
showArrows
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/UI/SubjectsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FC } from 'react';
import {
Card, CardGrid, Div, Group, Header, InfoRow, Subhead, Title,
} from '@vkontakte/vkui';
import { Examinations, ExaminationType } from '../../../../shared';
import { Examinations, ExaminationType } from '/diary-shared';

interface SubjectListProps {
semesters: Record<string, any[]>;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/UserInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
import { Icon28SchoolOutline, Icon32PrometeyCircleFillRed } from '@vkontakte/icons';
import bridge from '@vkontakte/vk-bridge';
import { useRouteNavigator } from '@vkontakte/vk-mini-apps-router';
import { Organization } from 'diary-shared';
import { getVkStorageData, getVkStorageKeys } from '../methods';
import { useModal } from '../modals/ModalContext';
import { useRateLimitExceeded } from '../hooks';
import { MODAL_COLLEGE_INFO } from '../modals/ModalRoot';
import { Organization } from '../../../shared';
import getCollegeInfo from '../methods/server/getCollegeInfo';
import useSnackbar from '../hooks/useSnackbar';
import logOut from '../utils/logOut';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/methods/server/getAds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NotificationsResponse } from 'diary-shared';
import { getCookie } from '../bridge/getCookie';
import { NotificationsResponse } from '../../../../shared';

const getAds = async (): Promise<NotificationsResponse[] | 418 | 429> => {
const cookie = await getCookie();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/methods/server/getAttestation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AttestationResponse } from 'diary-shared';
import { getCookie } from '../bridge/getCookie';
import { AttestationResponse } from '../../../../shared';
import { getUserId } from '../bridge/getUserId';

const getAttestation = async (): Promise<AttestationResponse | 418 | 429> => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/methods/server/getCollegeInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Organization } from '../../../../shared';
import { Organization } from 'diary-shared';
import { getCookie } from '../bridge/getCookie';

const getCollegeInfo = async (): Promise<Organization | 418 | 429> => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/methods/server/getLessons.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Day } from '../../../../shared';
import { Day } from 'diary-shared';
import formatDateForRequest from '../../utils/formatDateForRequest';
import { getUserId } from '../bridge/getUserId';
import { getCookie } from '../bridge/getCookie';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/methods/server/getPerformance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PerformanceCurrent } from '../../../../shared';
import { PerformanceCurrent } from 'diary-shared';
import { getCookie } from '../bridge/getCookie';
import { getUserId } from '../bridge/getUserId';

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/modals/LessonModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import {
Group, Header, InfoRow, ModalPage, ModalPageHeader, Separator, SimpleCell, Spacing, Text,
} from '@vkontakte/vkui';
import {
EAbsenceTypes, EAbsenceTypesDescription, Grade, Lesson, LessonType, LessonWorkType, TLesson,
} from '../../../shared';
EAbsenceTypes, EAbsenceTypesDescription, Lesson, LessonType, LessonWorkType, TLesson,
} from '/diary-shared';
import setDefaultMark from '../utils/setDefaultMark';
import textToLink from '../utils/textToLink';
import { cleanData } from './data';
import Mark from '../components/UI/Mark';
import { useModal } from './ModalContext';
import {Grade} from "../types";

interface ILessonModal {
id: string;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modals/ModalContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {
ReactNode, createContext, useContext, useState, useMemo,
} from 'react';
import { Lesson, Organization } from '../../../shared';
import { Lesson, Organization } from 'diary-shared';

const ModalContext = createContext<{
lessonModalData: Lesson | null;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modals/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Lesson } from '../../../shared';
import { Lesson } from 'diary-shared';

export const cleanData: Lesson = {
name: '',
Expand Down
23 changes: 23 additions & 0 deletions frontend/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,26 @@ export interface Storage {
key: string;
value: string
}

// FIXME: enum стал страшный и в целом enum многие по понятным причинам хейтят
// Поэтому когда-нибудь надо пофиксить
export enum Grade {
Five = 5,
Four = 4,
Three = 3,
Two = 2,
One = 1,
// Оценка пустая = долг, двойку не ставим!
'' = 'Д',
'Н' = 'Н',
// Кастыль :))
'Д' = 'Д',
'ДЗ' = 'ДЗ',
'О' = 'О'
}


type GradeKeys = keyof typeof Grade;

export type TextMark = GradeKeys;
export type TMark = typeof Grade[GradeKeys];
3 changes: 2 additions & 1 deletion frontend/src/utils/calculateAverageMark.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Grade, TextMark } from '../../../shared';
import { TextMark } from 'diary-shared';
import {Grade} from "../types";

const calculateAverageMark = (marks: TextMark[] | undefined): number | null => {
if (!marks || marks.length === 0) {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/utils/setDefaultMark.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Task, TextMark } from '../../../shared';
import { Task } from 'diary-shared';
import { TextMark } from '../../../shared';
// TODO: можно с помощью неё фиксить ошибки с неправильными оценами
const setDefaultMark = (task: Task): TextMark => {
if (task.isRequired && !task.mark) {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/views/Attestation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {
Button, ButtonGroup, Div, Link, Panel, Placeholder, ScreenSpinner, View,
} from '@vkontakte/vkui';
import { useActiveVkuiLocation, useRouteNavigator } from '@vkontakte/vk-mini-apps-router';
import { AttestationResponse } from 'diary-shared';
import getAttestation from '../methods/server/getAttestation';
import { AttestationResponse } from '../../../shared';
import PanelHeaderWithBack from '../components/UI/PanelHeaderWithBack';
import { useRateLimitExceeded } from '../hooks';
import SubjectList from '../components/UI/SubjectsList.tsx';
import { handleResponse } from '../utils/handleResponse.ts';
import SubjectList from '../components/UI/SubjectsList';
import { handleResponse } from '../utils/handleResponse';

interface IAttestation {
id: string;
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/views/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { useActiveVkuiLocation, useRouteNavigator } from '@vkontakte/vk-mini-apps-router';
import Hashes from 'jshashes';
import { Icon28DoorArrowLeftOutline, Icon28ErrorCircleOutline } from '@vkontakte/icons';
import { AuthData } from '../../../shared';
import { AuthData } from 'diary-shared';
import { appStorageSet, getCookie } from '../methods';
import { VIEW_SCHEDULE } from '../routes';
import { useSnackbar } from '../hooks';
Expand Down Expand Up @@ -85,14 +85,13 @@ const LoginForm: FC<{ id: string }> = ({ id }) => {
setPopout(<ScreenSpinner state='loading' />);
const response = await fetch(`${import.meta.env.VITE_SERVER_URL}/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=UTF-8',
origin,
},
body: JSON.stringify({
login,
password: passwordHashed,
}),
headers: {
"Access-Control-Allow-Origin": "*"
}
});
if (response.status === 401) {
console.log('401');
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
} from '@vkontakte/vkui';
import { useActiveVkuiLocation, useRouteNavigator } from '@vkontakte/vk-mini-apps-router';
import { Icon28ErrorCircleOutline } from '@vkontakte/icons';
import { NotificationsResponse } from 'diary-shared';
import PanelHeaderWithBack from '../components/UI/PanelHeaderWithBack';
import { handleResponse } from '../utils/handleResponse';
import getAds from '../methods/server/getAds';
import { useSnackbar } from '../hooks';
import { NotificationsResponse } from '../../../shared';
import SubtitleWithBorder from '../components/SubtitleWithBorder';

const Notifications: FC<{ id: string }> = ({ id }) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/Schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Icon28ErrorCircleOutline,
} from '@vkontakte/icons';
import { addDays, endOfWeek, startOfWeek } from '@vkontakte/vkui/dist/lib/date';
import { Day, PerformanceCurrent } from '../../../shared';
import { Day, PerformanceCurrent } from 'diary-shared';
import { getLessons, getPerformance } from '../methods';
import PanelHeaderWithBack from '../components/UI/PanelHeaderWithBack';
import Suspense from '../components/UI/Suspense';
Expand Down
2 changes: 1 addition & 1 deletion frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ export default defineConfig({
},
// Указывать только для dev сборки.
// Либо index'у вернуть его исходное имя, а переименовывать только при деплое
// base: 'index-b4.html',
base: 'index-b4.html',
})
2 changes: 1 addition & 1 deletion frontend/vk-hosting-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"static_path": "dist",
"app_id": 51740302,
"app_id": 51723411,
"endpoints": {
"mobile": "index-b4.html",
"mvk": "index-b4.html",
Expand Down
5 changes: 5 additions & 0 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,11 @@ dequal@^2.0.3:
resolved "https://registry.yarnpkg.com/dequal/-/dequal-2.0.3.tgz#2644214f1997d39ed0ee0ece72335490a7ac67be"
integrity sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==

diary-shared@^1.6.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/diary-shared/-/diary-shared-1.6.2.tgz#0df3513dfcb7215317f1d7824b4d713618930934"
integrity sha512-L9nP98OryhA8tS8LdOJaikcvcbaNLoljcgW+sTPBFwyjAznYKJ416T99csn77Kk89EHvPsnF2GIWk5kvF+cVyw==

dir-glob@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f"
Expand Down
Loading

0 comments on commit c59f033

Please sign in to comment.