From d1d345ca88849ebbe4ef4e106d9a027c729a4b8d Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Wed, 8 Dec 2021 20:47:06 +0300 Subject: [PATCH] feat: added courses page store --- src/components/Buttons/index.tsx | 8 +- src/components/SetCourseStatusButton/index.ts | 3 - .../components/CategoryList/CategoryItem.tsx | 10 ++- .../components/CategoryList/CategoryList.tsx | 10 ++- .../components/CourseList/CourseList.tsx | 14 ++-- .../CourseStatusTabs/CourseStatusTabs.tsx | 36 -------- .../components/CourseStatusTabs/index.ts | 3 - src/pages/courses/components/index.tsx | 31 +++++++ src/pages/courses/courses.tsx | 32 +++----- .../courses/edit/components/index.tsx} | 35 ++++---- src/pages/courses/edit/edit.tsx | 82 ++++++++++--------- src/stores/PageStore.ts | 4 + src/stores/pages/CoursesStore.ts | 30 +++++++ 13 files changed, 168 insertions(+), 130 deletions(-) delete mode 100644 src/components/SetCourseStatusButton/index.ts delete mode 100644 src/pages/courses/components/CourseStatusTabs/CourseStatusTabs.tsx delete mode 100644 src/pages/courses/components/CourseStatusTabs/index.ts create mode 100644 src/pages/courses/components/index.tsx rename src/{components/SetCourseStatusButton/SetCourseStatusButton.tsx => pages/courses/edit/components/index.tsx} (66%) create mode 100644 src/stores/pages/CoursesStore.ts diff --git a/src/components/Buttons/index.tsx b/src/components/Buttons/index.tsx index ff1f715..6b3b170 100644 --- a/src/components/Buttons/index.tsx +++ b/src/components/Buttons/index.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { ButtonProps, Button } from '@chakra-ui/button'; -import { AddIcon, EditIcon } from '@chakra-ui/icons'; +import { AddIcon, DeleteIcon, EditIcon } from '@chakra-ui/icons'; import { MdSave } from 'react-icons/md'; export const CreateButton: React.FC = props => ( @@ -9,6 +9,12 @@ export const CreateButton: React.FC = props => ( ); +export const DeleteButton: React.FC = props => ( + +); + export const EditButton: React.FC = props => ( @@ -38,8 +42,11 @@ const SetCourseStatusButton: React.FC = ({ @@ -48,5 +55,3 @@ const SetCourseStatusButton: React.FC = ({ return Components[status]; }; - -export default SetCourseStatusButton; diff --git a/src/pages/courses/edit/edit.tsx b/src/pages/courses/edit/edit.tsx index d6e02b6..d644009 100644 --- a/src/pages/courses/edit/edit.tsx +++ b/src/pages/courses/edit/edit.tsx @@ -1,8 +1,7 @@ import React from 'react'; import Helmet from 'react-helmet'; import { Redirect } from 'react-router-dom'; -import { Box, Heading, Text, Tab, TabList, Flex, Tabs, TabPanels, TabPanel, Button } from '@chakra-ui/react'; -import { DeleteIcon } from '@chakra-ui/icons'; +import { Box, Heading, Text, Tab, TabList, Flex, Tabs, TabPanels, TabPanel } from '@chakra-ui/react'; /** * Types @@ -14,7 +13,6 @@ import type { IPageProps } from '@educt/interfaces'; */ import LoadingPage from '@educt/components/LoadingPage'; import { EditCourseForm } from '@educt/components/Forms/CourseForm'; -import SetCourseStatusButton from '@educt/components/SetCourseStatusButton'; import DeleteCourseDialog from '@educt/components/Dialogs/DeleteCourseDialog'; import { StudentTableList, StudentTableRow } from './components/StudentTableList'; import LessonList from './components/LessonList'; @@ -26,6 +24,9 @@ import { useParams } from 'react-router-dom'; import { useRootStore } from '@educt/hooks/useRootStore'; import { useFetchCourse } from '@educt/hooks/queries'; import { useDisclosure } from '@chakra-ui/hooks'; +import { PageContent, PageWrapper } from '@educt/components/PageElements'; +import { DeleteButton } from '@educt/components/Buttons'; +import { StatusButton } from './components'; /** * Course editor @@ -53,55 +54,58 @@ const EditCoursePage: React.FC = () => { if (!course || isLoading) return ; return ( - <> + Editing {course.title} + + Course editor {course.title} - - + + - - - - Info - Lessons - Students - - - - - - - - - - - - - - - - - + + + + + Info + Lessons + Students + + + + + + + + + + + + + + + + + + + ); }; diff --git a/src/stores/PageStore.ts b/src/stores/PageStore.ts index 4450700..da2c98f 100644 --- a/src/stores/PageStore.ts +++ b/src/stores/PageStore.ts @@ -1,10 +1,13 @@ import { makeAutoObservable } from 'mobx'; +import CoursesStore from './pages/CoursesStore'; import EditCourseStore from './pages/EditCourseStore'; import RootStore from './RootStore'; export default class PageStore { public root: RootStore; + public coursesStore: CoursesStore; + public editCourseStore: EditCourseStore; constructor(root: RootStore) { @@ -13,6 +16,7 @@ export default class PageStore { /** * Pages */ + this.coursesStore = new CoursesStore(this); this.editCourseStore = new EditCourseStore(this); makeAutoObservable(this); diff --git a/src/stores/pages/CoursesStore.ts b/src/stores/pages/CoursesStore.ts new file mode 100644 index 0000000..101ee8d --- /dev/null +++ b/src/stores/pages/CoursesStore.ts @@ -0,0 +1,30 @@ +import { makeAutoObservable } from 'mobx'; +import { CourseStatusEnum } from '@educt/enums'; +import PageStore from '../PageStore'; + +/** + * Types + */ +import type { ICategory } from '@educt/interfaces'; + +export default class CoursesStore { + public pageStore: PageStore; + + public selectedCategory: ICategory | null = null; + + public showedStatus: CourseStatusEnum | undefined; + + constructor(pageStore: PageStore) { + this.pageStore = pageStore; + + makeAutoObservable(this); + } + + public setSelectedCategory(category: ICategory | null): void { + this.selectedCategory = category; + } + + public setShowedStatus(newStatus: CourseStatusEnum | undefined): void { + this.showedStatus = newStatus; + } +}