diff --git a/src/pages/courses/components/CategoryList/CategoryItem.tsx b/src/pages/courses/components/CategoryList/CategoryItem.tsx index 3042c2d..79f5a5c 100644 --- a/src/pages/courses/components/CategoryList/CategoryItem.tsx +++ b/src/pages/courses/components/CategoryList/CategoryItem.tsx @@ -21,7 +21,9 @@ const CategoryItem: React.FC = ({ category }) => { /** * Handle click on change category */ - const onCategoryChange = () => setSelectedCategory(category); + const onCategoryChange = () => { + setSelectedCategory(category); + }; return ( = ({ categories }) => { const { selectedCategory, setSelectedCategory } = useContext(CoursesPageContext); + + /** + * Handle on changing category + */ + useEffect(() => { + console.log(`[LOG:] Selected category: ${selectedCategory?.title}`); + }, [selectedCategory]); + return ( diff --git a/src/pages/courses/components/CategoryList/CategoryListLoading.tsx b/src/pages/courses/components/CategoryList/CategoryListLoading.tsx new file mode 100644 index 0000000..87b6e7c --- /dev/null +++ b/src/pages/courses/components/CategoryList/CategoryListLoading.tsx @@ -0,0 +1,16 @@ +import React from 'react'; +import { Flex, Skeleton } from '@chakra-ui/react'; + +const CategoryListLoading: React.FC = () => { + return ( + + + + + + + + ); +}; + +export default CategoryListLoading; diff --git a/src/pages/courses/index.tsx b/src/pages/courses/index.tsx index 1aa131e..e001119 100644 --- a/src/pages/courses/index.tsx +++ b/src/pages/courses/index.tsx @@ -17,6 +17,7 @@ import CategoryList from './components/CategoryList'; import { useRootStore } from 'hooks/useRootStore'; import { CoursesPageContextProvider } from 'providers'; import { useErrorHandler } from 'react-error-boundary'; +import CategoryListLoading from './components/CategoryList/CategoryListLoading'; /** * Courses page @@ -29,8 +30,10 @@ const CoursesPage: React.FC = ({ title }) => { const handleError = useErrorHandler(); useEffect(() => { - categoryStore.loadCategories().catch(error => handleError(error)); - }, [categoryStore, handleError]); + if (me !== null) { + categoryStore.loadCategories().catch(error => handleError(error)); + } + }, [me, categoryStore, handleError]); /** * TODO: Loading page for courses @@ -62,7 +65,14 @@ const CoursesPage: React.FC = ({ title }) => { )} - + {/* Category List Rendering */} + {categoryStore.categories !== null ? ( + + ) : ( + + )} + + {/* Course List Rendering */} diff --git a/src/pages/users/components/UserList/UserList.tsx b/src/pages/users/components/UserList/UserList.tsx index 87102a1..3d3102c 100644 --- a/src/pages/users/components/UserList/UserList.tsx +++ b/src/pages/users/components/UserList/UserList.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import { observer } from 'mobx-react'; import { ChevronLeftIcon, ChevronRightIcon } from '@chakra-ui/icons'; import { Flex, Box, Stack, Text } from '@chakra-ui/layout'; import { Button } from '@chakra-ui/button'; @@ -155,4 +154,4 @@ const UserList: React.FC = ({ users, pagination }) => { ); }; -export default observer(UserList); +export default UserList; diff --git a/src/stores/CategoryStore.ts b/src/stores/CategoryStore.ts index 0457faa..f86c09b 100644 --- a/src/stores/CategoryStore.ts +++ b/src/stores/CategoryStore.ts @@ -9,7 +9,7 @@ export default class CategoryStore { public categoryService: CategoryService; - public categories: ICategory[] = []; + public categories: ICategory[] | null = null; constructor(root: RootStore, api: AxiosInstance) { this.root = root;