mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 18:29:15 +03:00
feat: render courses by status param
This commit is contained in:
parent
a7792983fd
commit
653a71dc67
@ -27,4 +27,6 @@ export const UsersPageContext = createContext<UsersPageContextType>({
|
|||||||
export const CoursesPageContext = createContext<CoursesPageContextType>({
|
export const CoursesPageContext = createContext<CoursesPageContextType>({
|
||||||
selectedCategory: undefined,
|
selectedCategory: undefined,
|
||||||
setSelectedCategory: () => {},
|
setSelectedCategory: () => {},
|
||||||
|
courseStatus: undefined,
|
||||||
|
setCourseStatus: () => {},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -29,11 +29,11 @@ type CourseListPropsType = {
|
|||||||
|
|
||||||
const CourseList: React.FC<CourseListPropsType> = ({ courses, isLoading }) => {
|
const CourseList: React.FC<CourseListPropsType> = ({ courses, isLoading }) => {
|
||||||
const { courseStore } = useRootStore();
|
const { courseStore } = useRootStore();
|
||||||
const { selectedCategory } = useContext(CoursesPageContext);
|
const { selectedCategory, courseStatus } = useContext(CoursesPageContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
courseStore.loadCourses({ category_id: selectedCategory?.id });
|
courseStore.loadCourses({ category_id: selectedCategory?.id, status: courseStatus });
|
||||||
}, [courseStore, selectedCategory]);
|
}, [courseStore, selectedCategory, courseStatus]);
|
||||||
|
|
||||||
if (isLoading || courses === null) {
|
if (isLoading || courses === null) {
|
||||||
return <CourseListLoading />;
|
return <CourseListLoading />;
|
||||||
@ -60,7 +60,7 @@ const CourseList: React.FC<CourseListPropsType> = ({ courses, isLoading }) => {
|
|||||||
</Grid>
|
</Grid>
|
||||||
) : (
|
) : (
|
||||||
<Box textAlign='center' mt='10' userSelect='none'>
|
<Box textAlign='center' mt='10' userSelect='none'>
|
||||||
<Text color='gray.500'>There are no courses in this category.</Text>
|
<Text color='gray.500'>There are no courses in this category {courseStatus && 'or with this status'}.</Text>
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -0,0 +1,28 @@
|
|||||||
|
import React, { useContext } from 'react';
|
||||||
|
import { Tabs, TabList, Tab } from '@chakra-ui/react';
|
||||||
|
import { CoursesPageContext } from 'contexts';
|
||||||
|
import { CourseStatusEnum } from 'enums';
|
||||||
|
|
||||||
|
type CourseStatusTabsProps = {};
|
||||||
|
|
||||||
|
const CourseStatusTabs: React.FC<CourseStatusTabsProps> = () => {
|
||||||
|
const { setCourseStatus } = useContext(CoursesPageContext);
|
||||||
|
const handleChangeStatus = (status: CourseStatusEnum | undefined) => setCourseStatus(status);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tabs>
|
||||||
|
<TabList justifyContent='center'>
|
||||||
|
<Tab onClick={() => handleChangeStatus(undefined)}>All</Tab>
|
||||||
|
{Object.values(CourseStatusEnum).map(status => {
|
||||||
|
return (
|
||||||
|
<Tab key={status} onClick={() => handleChangeStatus(status)}>{`${status.charAt(0).toUpperCase()}${status
|
||||||
|
.substr(1)
|
||||||
|
.toLowerCase()}`}</Tab>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</TabList>
|
||||||
|
</Tabs>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CourseStatusTabs;
|
||||||
3
src/pages/courses/components/CourseStatusTabs/index.ts
Normal file
3
src/pages/courses/components/CourseStatusTabs/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import CourseStatusTabs from './CourseStatusTabs';
|
||||||
|
|
||||||
|
export default CourseStatusTabs;
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
import { Flex, Tabs, TabList, Tab, Box, Heading, Text, Button } from '@chakra-ui/react';
|
import { Flex, Box, Heading, Text, Button } from '@chakra-ui/react';
|
||||||
|
|
||||||
import { IPageProps } from 'interfaces';
|
import { IPageProps } from 'interfaces';
|
||||||
import { AddIcon } from '@chakra-ui/icons';
|
import { AddIcon } from '@chakra-ui/icons';
|
||||||
@ -17,6 +17,7 @@ import LoadingPage from 'components/LoadingPage';
|
|||||||
*/
|
*/
|
||||||
import { useRootStore } from 'hooks/useRootStore';
|
import { useRootStore } from 'hooks/useRootStore';
|
||||||
import { CoursesPageContextProvider } from 'providers';
|
import { CoursesPageContextProvider } from 'providers';
|
||||||
|
import CourseStatusTabs from './components/CourseStatusTabs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Courses page
|
* Courses page
|
||||||
@ -45,15 +46,7 @@ const CoursesPage: React.FC<IPageProps> = ({ title }) => {
|
|||||||
)}
|
)}
|
||||||
</Flex>
|
</Flex>
|
||||||
<Box mt='7'>
|
<Box mt='7'>
|
||||||
{(me.isAdmin || me.isTeacher) && (
|
{(me.isAdmin || me.isTeacher) && <CourseStatusTabs />}
|
||||||
<Tabs>
|
|
||||||
<TabList justifyContent='center'>
|
|
||||||
<Tab>All</Tab>
|
|
||||||
<Tab>Published</Tab>
|
|
||||||
<Tab>Draft</Tab>
|
|
||||||
</TabList>
|
|
||||||
</Tabs>
|
|
||||||
)}
|
|
||||||
<Box mt='5'>
|
<Box mt='5'>
|
||||||
<CategoryList categories={categoryStore.categories} isLoading={categoryStore.isLoading} />
|
<CategoryList categories={categoryStore.categories} isLoading={categoryStore.isLoading} />
|
||||||
<CourseList courses={courseStore.courses} isLoading={courseStore.isLoading} />
|
<CourseList courses={courseStore.courses} isLoading={courseStore.isLoading} />
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { CoursesPageContext, ProfilePageContext, StoreContext, UsersPageContext
|
|||||||
import { ProfilePageDataType, ProfilePageStatusType, SearchingRoleStateType } from 'types';
|
import { ProfilePageDataType, ProfilePageStatusType, SearchingRoleStateType } from 'types';
|
||||||
import RootStore from 'stores/RootStore';
|
import RootStore from 'stores/RootStore';
|
||||||
import { ICategory, IUser } from 'interfaces';
|
import { ICategory, IUser } from 'interfaces';
|
||||||
|
import { CourseStatusEnum } from 'enums';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Root store context provider
|
* Root store context provider
|
||||||
@ -62,9 +63,10 @@ export const UsersPageContextProvider: React.FC = ({ children }) => {
|
|||||||
*/
|
*/
|
||||||
export const CoursesPageContextProvider: React.FC = ({ children }) => {
|
export const CoursesPageContextProvider: React.FC = ({ children }) => {
|
||||||
const [selectedCategory, setSelectedCategory] = useState<ICategory | undefined>(undefined);
|
const [selectedCategory, setSelectedCategory] = useState<ICategory | undefined>(undefined);
|
||||||
|
const [courseStatus, setCourseStatus] = useState<CourseStatusEnum | undefined>(undefined);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CoursesPageContext.Provider value={{ selectedCategory, setSelectedCategory }}>
|
<CoursesPageContext.Provider value={{ selectedCategory, setSelectedCategory, courseStatus, setCourseStatus }}>
|
||||||
{children}
|
{children}
|
||||||
</CoursesPageContext.Provider>
|
</CoursesPageContext.Provider>
|
||||||
);
|
);
|
||||||
|
|||||||
10
src/types/index.d.ts
vendored
10
src/types/index.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
import { UserRoleEnum } from 'enums';
|
import { CourseStatusEnum, UserRoleEnum } from 'enums';
|
||||||
import { ICategory, IUser } from 'interfaces';
|
import { ICategory, IUser } from 'interfaces';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { IconType } from 'react-icons/lib';
|
import { IconType } from 'react-icons/lib';
|
||||||
@ -76,10 +76,16 @@ export type UsersPageContextType = {
|
|||||||
|
|
||||||
export type CoursesPageContextType = {
|
export type CoursesPageContextType = {
|
||||||
/**
|
/**
|
||||||
* Filter courses by switching caterory
|
* Filter courses by caterory
|
||||||
*/
|
*/
|
||||||
selectedCategory: ICategory | undefined;
|
selectedCategory: ICategory | undefined;
|
||||||
setSelectedCategory: React.Dispatch<React.SetStateAction<ICategory | undefined>>;
|
setSelectedCategory: React.Dispatch<React.SetStateAction<ICategory | undefined>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter courses by status
|
||||||
|
*/
|
||||||
|
courseStatus: CourseStatusEnum | undefined;
|
||||||
|
setCourseStatus: React.Dispatch<React.SetStateAction<CourseStatusEnum | undefined>>;
|
||||||
};
|
};
|
||||||
export type FetchCoursesParams = {
|
export type FetchCoursesParams = {
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user