Skip to content

Commit

Permalink
Merge pull request #224 from kpi-ua/staging
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado-x authored Sep 6, 2024
2 parents 6604e2c + eb083e3 commit 588a174
Show file tree
Hide file tree
Showing 81 changed files with 919 additions and 733 deletions.
39 changes: 38 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^14.4.3",
"@types/lodash-es": "^4.17.12",
"@types/material-ui": "^0.21.17",
"@types/node": "^20.14.2",
"@types/react": "^17.0.80",
Expand All @@ -15,6 +16,7 @@
"@types/styled-system": "^5.1.22",
"axios": "^0.27.2",
"clsx": "^1.2.0",
"lodash-es": "^4.17.21",
"moment": "^2.29.4",
"react": "17.0.2",
"react-dom": "^17.0.2",
Expand Down
25 changes: 15 additions & 10 deletions src/api/fullList.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { Group } from '../models/Group';
import { Lecturer } from '../models/Lecturer';
import { PagedResponse } from '../models/PagedResponse';
import Http from "./index";

export const getAllLecturers = () => {
export const getAllLecturers = (): Promise<PagedResponse<Lecturer[]>> => {
return Http.get("/schedule/lecturer/list").then(({ data }) => data);
};

export const getAllGroups = () => {
return Http.get("/schedule/groups").then(({ data }) => {
return {
data: data.data.map((row: {name: string, faculty: string, id: string}) => ({
name: `${row.name.trim()} (${row.faculty.trim()})`,
id: row.id,
})),
};
});
export const getAllGroups = async (): Promise<PagedResponse<Group[]>> => {
const response = await Http.get<PagedResponse<Group[]>>("/schedule/groups")

return {
...response.data,
data: response.data.data.map(row => ({
...row,
name: `${row.name.trim()} (${row.faculty.trim()})`,
id: row.id,
}))
};
};
7 changes: 4 additions & 3 deletions src/api/getCurrentDateValues.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CurrentTime } from '../models/CurrentTime';
import { PagedResponse } from '../models/PagedResponse';
import Http from './index';

export const getCurrentDateValues = () => {
return Http.get('/time/current')
.then(res => res.data);
export const getCurrentDateValues = (): Promise<PagedResponse<CurrentTime>> => {
return Http.get('/time/current').then(res => res.data);
};
10 changes: 7 additions & 3 deletions src/api/schedule.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { Exam } from '../models/Exam';
import { LecturerLesson } from '../models/LecturerLesson';
import { PagedResponse } from '../models/PagedResponse';
import { StudentLesson } from '../models/StudentLesson';
import Http from './index';

export const getScheduleByLecturer = (lecturerId: string) => {
export const getScheduleByLecturer = (lecturerId: string): Promise<PagedResponse<LecturerLesson[]>> => {
return Http.get('/schedule/lecturer?lecturerId=' + lecturerId)
.then(res => res.data);
}

export const getScheduleByGroup = (groupId: string) => {
export const getScheduleByGroup = (groupId: string): Promise<PagedResponse<StudentLesson[]>> => {
return Http.get('/schedule/lessons?groupId=' + groupId)
.then(res => res.data);
}

export const getExamsByGroup = (groupName: string) => {
export const getExamsByGroup = (groupName: string): Promise<PagedResponse<Exam[]>> => {
return Http.get('/exams/group?groupId=' + groupName)
.then(res => res.data);
}
2 changes: 1 addition & 1 deletion src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GroupContextProvider } from "../common/context/groupContext";
import { LecturerContextProvider } from "../common/context/lecturerContext";
import { PreloadedListsContextProvider } from "../common/context/preloadedListsContext";
import { WeekContextProvider } from "../common/context/weekContext";
import { useCurrentDateParams } from "../common/utils/useCurrentDateParams";
import { useCurrentDateParams } from "../common/hooks/useCurrentDateParams";
import ThemeContextProvider from "../common/context/themeContext";
import Navbar from "../containers/navbar";
import ScheduleRouter from "../containers/router";
Expand Down
37 changes: 20 additions & 17 deletions src/common/constants/dayOptions.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { MODES } from './modes';
import { ListOption } from '../../types/ListOption';
import { ScreenSize } from '../../types/ScreenSize';

export const DAY_OPTIONS = {
[MODES.EXTRA_SMALL]: [
{label: 'ПН', value: '0-1'},
{label: 'ВТ', value: '1-2'},
{label: 'СР', value: '2-3'},
{label: 'ЧТ', value: '3-4'},
{label: 'ПТ', value: '4-5'},
{label: 'СБ', value: '5-6'},
export type DaysRange = `${number}-${number}`;

export const DAY_OPTIONS: Partial<Record<ScreenSize, ListOption<DaysRange>[]>> = {
[ScreenSize.ExtraSmall]: [
{label: 'ПН', value: '1-1'},
{label: 'ВТ', value: '2-2'},
{label: 'СР', value: '3-3'},
{label: 'ЧТ', value: '4-4'},
{label: 'ПТ', value: '5-5'},
{label: 'СБ', value: '6-6'},
],
[ScreenSize.Small]: [
{label: 'ПН-ВТ', value: '1-2'},
{label: 'СР-ЧТ', value: '3-4'},
{label: 'ПТ-СБ', value: '5-6'},
],
[MODES.SMALL]: [
{label: 'ПН-ВТ', value: '0-2'},
{label: 'СР-ЧТ', value: '2-4'},
{label: 'ПТ-СБ', value: '4-6'},
[ScreenSize.Medium]: [
{label: 'ПН-СР', value: '1-3'},
{label: 'ЧТ-СБ', value: '4-6'},
],
[MODES.MEDIUM]: [
{label: 'ПН-СР', value: '0-3'},
{label: 'ЧТ-СБ', value: '3-6'},
]
};
6 changes: 0 additions & 6 deletions src/common/constants/modes.ts

This file was deleted.

8 changes: 8 additions & 0 deletions src/common/constants/screenSize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ScreenSize } from '../../types/ScreenSize';

export const SCREEN_SIZES: Record<ScreenSize, string> = {
[ScreenSize.Big]: '1441px',
[ScreenSize.Medium]: '1440px',
[ScreenSize.Small]: '988px',
[ScreenSize.ExtraSmall]: '639px',
};
6 changes: 4 additions & 2 deletions src/common/constants/theme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const theme = {
import { Theme } from '../../types/Theme';

export const theme: Record<Theme, Object> = {
light: {
bgPrimary: 'linear-gradient(90deg, #FFEFF2 0%, #DBE9FE 100%)',
bgHeader: 'linear-gradient(180deg, #FFFFFF 0%, rgba(255, 255, 255, 0.5) 100%)',
Expand All @@ -23,4 +25,4 @@ export const theme = {
currentDayContainer: 'linear-gradient(180deg, rgba(54, 54, 55, 0) 0%, rgba(54, 54, 55, 0.5) 10.73%, #363637 55%, rgba(54, 54, 55, 0.5) 89.9%, rgba(54, 54, 55, 0.29) 100%)',
svgPrimaryFilter: 'invert(100%) sepia(0%) saturate(0%) hue-rotate(46deg) brightness(100%) contrast(103%)',
}
} as any;
};
14 changes: 6 additions & 8 deletions src/common/context/groupContext.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import React, { createContext, useContext, useState } from "react";
import { Group } from '../../models/Group';

interface Props {
children: React.ReactNode
}

interface GroupContextType {
group?: any;
setGroup: React.Dispatch<any>;
group?: Group;
setGroup: React.Dispatch<React.SetStateAction<Group | undefined>>;
};


const defaultContext: GroupContextType = {
const GroupContext = createContext<GroupContextType>({
setGroup: () => {},
};

const GroupContext = createContext<GroupContextType>(defaultContext);
});

export const useGroupContext = () => useContext(GroupContext);

export const GroupContextProvider: React.FC<Props> = ({ children }) => {
const [group, setGroup] = useState<any>();
const [group, setGroup] = useState<Group>();

const params: GroupContextType = { setGroup, group };

Expand Down
19 changes: 12 additions & 7 deletions src/common/context/lecturerContext.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
import React, { createContext, useContext, useState, ReactNode, FC } from 'react';
import { Lecturer } from '../../models/Lecturer';

interface Props {
children: ReactNode;
}

interface LecturerContextType {
lecturer: string | null; // Change this to the actual type of lecturer
setLecturer: React.Dispatch<React.SetStateAction<string | null>>;
lecturer?: Lecturer;
setLecturer: React.Dispatch<React.SetStateAction<Lecturer | undefined>>;
}

const LecturerContext = createContext<LecturerContextType | null>(null);
const LecturerContext = createContext<LecturerContextType>({
setLecturer: () => ({}),
});

export const useLecturerContext = () => {
const context = useContext(LecturerContext);

if (context === null) {
throw new Error('useLecturerContext must be used within a LecturerContextProvider');
}

return context;
};

export const LecturerContextProvider: FC<Props> = ({ children }) => {
const [lecturer, setLecturer] = useState<string | null>(null);
const params = { lecturer, setLecturer };
const [lecturer, setLecturer] = useState<Lecturer>();

const params: LecturerContextType = { lecturer, setLecturer };

return (
<LecturerContext.Provider value={params}>
{children}
Expand Down
14 changes: 10 additions & 4 deletions src/common/context/preloadedListsContext.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import React, { createContext, useContext, useEffect, useState } from "react";
import { getAllGroups, getAllLecturers } from "../../api/fullList";
import { Group } from '../../models/Group';
import { Lecturer } from '../../models/Lecturer';

interface Props {
children: React.ReactNode;
}

interface ContextType {
groups: any[];
lecturers: any[];
groups: Group[];
lecturers: Lecturer[];
}

const PreloadedListsContext = createContext<ContextType | null>(null);
const PreloadedListsContext = createContext<ContextType>({
groups: [],
lecturers: [],
});

export const usePreloadedListContext = () => useContext(PreloadedListsContext);
// TODO add exams here

// TODO: add exams here
export const PreloadedListsContextProvider: React.FC<Props> = ({
children,
}) => {
Expand Down
Loading

0 comments on commit 588a174

Please sign in to comment.