mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 18:29:15 +03:00
refactor: fetch course with status PUBLISHED only in STUDENT role
This commit is contained in:
parent
653a71dc67
commit
775dbff54e
@ -21,6 +21,7 @@ import { useRootStore } from 'hooks/useRootStore';
|
|||||||
* Contexts
|
* Contexts
|
||||||
*/
|
*/
|
||||||
import { CoursesPageContext } from 'contexts';
|
import { CoursesPageContext } from 'contexts';
|
||||||
|
import { CourseStatusEnum } from 'enums';
|
||||||
|
|
||||||
type CourseListPropsType = {
|
type CourseListPropsType = {
|
||||||
courses: Omit<ICourse, 'teacher' | 'students' | 'lessons'>[] | null;
|
courses: Omit<ICourse, 'teacher' | 'students' | 'lessons'>[] | null;
|
||||||
@ -28,12 +29,20 @@ type CourseListPropsType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const CourseList: React.FC<CourseListPropsType> = ({ courses, isLoading }) => {
|
const CourseList: React.FC<CourseListPropsType> = ({ courses, isLoading }) => {
|
||||||
const { courseStore } = useRootStore();
|
const {
|
||||||
|
userStore: { me },
|
||||||
|
courseStore,
|
||||||
|
} = useRootStore();
|
||||||
const { selectedCategory, courseStatus } = useContext(CoursesPageContext);
|
const { selectedCategory, courseStatus } = useContext(CoursesPageContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
courseStore.loadCourses({ category_id: selectedCategory?.id, status: courseStatus });
|
if (me !== null) {
|
||||||
}, [courseStore, selectedCategory, courseStatus]);
|
courseStore.loadCourses({
|
||||||
|
category_id: selectedCategory?.id,
|
||||||
|
status: me.isAdmin || me.isTeacher ? courseStatus : CourseStatusEnum.PUBLISHED,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [courseStore, selectedCategory, courseStatus, me]);
|
||||||
|
|
||||||
if (isLoading || courses === null) {
|
if (isLoading || courses === null) {
|
||||||
return <CourseListLoading />;
|
return <CourseListLoading />;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user