diff --git a/src/components/ColorModeSwitcher/ColorModeSwitcher.tsx b/src/components/ColorModeSwitcher/ColorModeSwitcher.tsx index bdeb9a5..0ab80da 100644 --- a/src/components/ColorModeSwitcher/ColorModeSwitcher.tsx +++ b/src/components/ColorModeSwitcher/ColorModeSwitcher.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { useColorMode, useColorModeValue, IconButton, IconButtonProps } from '@chakra-ui/react'; import { FaMoon, FaSun } from 'react-icons/fa'; -type ColorModeSwitcherProps = Omit; +export type ColorModeSwitcherProps = Omit; const ColorModeSwitcher: React.FC = props => { const { toggleColorMode } = useColorMode(); diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx deleted file mode 100644 index 9cae6d4..0000000 --- a/src/components/Header/Header.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import React from 'react'; -import { observer } from 'mobx-react'; -import { Flex, Box } from '@chakra-ui/react'; - -/** - * Components - */ -import Logo from '@educt/components/Logo'; -import NavMobile from '@educt/components/Nav/Mobile'; -import ColorModeSwitcher from '@educt/components/ColorModeSwitcher'; -import ProfileMenu from './ProfileMenu'; -import NotificationsMenu from './NotificationsMenu'; - -/** - * Hooks - */ -import { useMediaQuery } from '@chakra-ui/media-query'; -import { useColorModeValue } from '@chakra-ui/color-mode'; - -const Header: React.FC = () => { - const [isDesktop] = useMediaQuery('(min-width: 992px)'); - - return ( - - - - {isDesktop && ( - - - - - - )} - {!isDesktop && } - - - ); -}; - -export default observer(Header); diff --git a/src/components/Header/Logo.tsx b/src/components/Header/Logo.tsx new file mode 100644 index 0000000..94c83fc --- /dev/null +++ b/src/components/Header/Logo.tsx @@ -0,0 +1,14 @@ +import React from 'react'; +import { Link as ReactRouterLink } from 'react-router-dom'; +import { Box, BoxProps, Link } from '@chakra-ui/react'; +import LogoIcon from '@educt/components/Logo'; + +const Logo: React.FC = props => ( + + + + + +); + +export { Logo }; diff --git a/src/components/Header/Notifications.tsx b/src/components/Header/Notifications.tsx new file mode 100644 index 0000000..74e2c6e --- /dev/null +++ b/src/components/Header/Notifications.tsx @@ -0,0 +1,53 @@ +import React from 'react'; +import { Menu, MenuButton, MenuList, MenuGroup, IconButton, MenuDivider } from '@chakra-ui/react'; +import { Skeleton } from '@chakra-ui/skeleton'; +import { MdNotifications } from 'react-icons/md'; +import { useRootStore } from '@educt/hooks/useRootStore'; +import { observer } from 'mobx-react'; + +export interface INotificationsProps { + count?: number | undefined; +} + +const Notifications: React.FC = observer(props => { + const { + userStore: { me }, + } = useRootStore(); + + const { count, ...menuProps } = props; + + if (me === null) { + return ; + } + + return ( + + } + _after={{ + content: `"${count && count > 0 && count}"`, + display: `${count && count > 0 ? 'block' : 'none'}`, + position: 'absolute', + top: '5px', + right: '5px', + background: '#E53E3E', + color: '#fff', + fontSize: '10px', + width: '15px', + height: '15px', + borderRadius: '100%', + }} + /> + + + + + + + ); +}); + +export { Notifications }; diff --git a/src/components/Header/NotificationsMenu.tsx b/src/components/Header/NotificationsMenu.tsx deleted file mode 100644 index a35d7cc..0000000 --- a/src/components/Header/NotificationsMenu.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import React from 'react'; -import { Box } from '@chakra-ui/layout'; -import { Skeleton } from '@chakra-ui/skeleton'; -import { Button } from '@chakra-ui/button'; -import { MdNotifications } from 'react-icons/md'; -import { useRootStore } from '@educt/hooks/useRootStore'; -import { observer } from 'mobx-react'; - -const NotificationsMenu: React.FC = () => { - const { userStore } = useRootStore(); - - if (userStore.me === null) { - return ; - } - - return ( - - ); -}; - -export default observer(NotificationsMenu); diff --git a/src/components/Header/ProfileMenu.tsx b/src/components/Header/Profile.tsx similarity index 77% rename from src/components/Header/ProfileMenu.tsx rename to src/components/Header/Profile.tsx index cd44d81..a517401 100644 --- a/src/components/Header/ProfileMenu.tsx +++ b/src/components/Header/Profile.tsx @@ -24,11 +24,13 @@ import UserBadge from '@educt/components/UserBadge'; */ import { useLogout } from '@educt/hooks/queries'; -const ProfileMenu: React.FC = () => { - const { userStore } = useRootStore(); +const Profile: React.FC = observer(() => { + const { + userStore: { me }, + } = useRootStore(); const { logout } = useLogout(); - if (userStore.me === null) { + if (me === null) { return ; } @@ -37,15 +39,15 @@ const ProfileMenu: React.FC = () => { - + - {userStore.me.fullname} + {me.fullname} - + - + @@ -62,6 +64,6 @@ const ProfileMenu: React.FC = () => { ); -}; +}); -export default observer(ProfileMenu); +export { Profile }; diff --git a/src/components/Header/index.ts b/src/components/Header/index.ts deleted file mode 100644 index a9ce105..0000000 --- a/src/components/Header/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import Header from './Header'; - -export default Header; diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx new file mode 100644 index 0000000..65fed94 --- /dev/null +++ b/src/components/Header/index.tsx @@ -0,0 +1,48 @@ +import React from 'react'; +import { Flex, Box, BoxProps } from '@chakra-ui/react'; +import { Logo } from './Logo'; +import { Profile } from './Profile'; +import { INotificationsProps, Notifications } from './Notifications'; +import ColorModeSwitcher from '@educt/components/ColorModeSwitcher'; +import NavMobile from '@educt/components/Nav/Mobile'; +import type { ColorModeSwitcherProps } from '../ColorModeSwitcher/ColorModeSwitcher'; + +/** + * Hooks + */ +import { useColorModeValue, useMediaQuery } from '@chakra-ui/react'; + +interface IHeaderComposition { + Logo: React.FC; + ThemeSwitcher: React.FC; + Notifications: React.FC; + Profile: React.FC; +} + +const Header: React.FC & IHeaderComposition = ({ children }) => { + const [isDesktop] = useMediaQuery('(min-width: 992px)'); + + return ( + + + {isDesktop ? children : } + + + ); +}; + +Header.Logo = Logo; +Header.ThemeSwitcher = props => ; +Header.Notifications = Notifications; +Header.Profile = Profile; + +export default Header; diff --git a/src/components/Layout/Layout.tsx b/src/components/Layout/Layout.tsx index 7823ab1..afc38bd 100644 --- a/src/components/Layout/Layout.tsx +++ b/src/components/Layout/Layout.tsx @@ -28,12 +28,14 @@ import { useRootStore } from '@educt/hooks/useRootStore'; */ import { SocketContext } from '@educt/contexts'; -type LayoutPropsType = { roles: UserRoleEnum[] | undefined }; +interface ILayoutProps { + roles?: UserRoleEnum[] | undefined; +} /** * Render the current page using layout */ -const Layout: React.FC = ({ children, roles }) => { +const Layout: React.FC = ({ children, roles }) => { const { userStore } = useRootStore(); const { socket } = useContext(SocketContext); const handleError = useErrorHandler(); @@ -69,7 +71,14 @@ const Layout: React.FC = ({ children, roles }) => { return ( <> -
+
+ + + + + + +
diff --git a/src/components/Nav/Mobile/index.tsx b/src/components/Nav/Mobile/index.tsx index 879b5f7..6918a8f 100644 --- a/src/components/Nav/Mobile/index.tsx +++ b/src/components/Nav/Mobile/index.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { observer } from 'mobx-react'; import { Link as ReactRouterLink } from 'react-router-dom'; -import { IconButton, Skeleton } from '@chakra-ui/react'; +import { IconButton, Skeleton, Divider } from '@chakra-ui/react'; import { Avatar } from '@chakra-ui/avatar'; import { Flex, Box, Text, Link } from '@chakra-ui/layout'; import { Drawer, DrawerOverlay, DrawerContent, DrawerBody } from '@chakra-ui/modal'; @@ -36,16 +36,19 @@ const NavMobile: React.FC = () => { - + - + - + + {me !== null ? ( = ({ course }) => { - return ( - - - - - {course.title} - - - - - {course.category.title} - - - - - - - {course.lessons_count} lessons - - - Last update {moment(course.created_at).format('ll')} - - - - ); -}; - -export default CourseItem; diff --git a/src/pages/profile/components/CourseList/CourseList.tsx b/src/pages/profile/components/CourseList/CourseList.tsx deleted file mode 100644 index 2c13ed7..0000000 --- a/src/pages/profile/components/CourseList/CourseList.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import React from 'react'; -import { Box, Text, Stack } from '@chakra-ui/layout'; - -/** - * Types - */ -import { IMe } from '@educt/interfaces'; - -/** - * Components - */ -import CourseItem from './CourseItem'; - -type CourseListPropsType = { - courses: IMe['courses']; -}; - -const CourseList: React.FC = ({ courses }) => { - if (courses === undefined) return null; - - if (courses.length === 0) { - return ( - - - You are not a member of any course - - - ); - } - - return ( - - {courses.map(course => ( - - ))} - - ); -}; - -export default CourseList; diff --git a/src/pages/profile/components/CourseList/index.ts b/src/pages/profile/components/CourseList/index.ts deleted file mode 100644 index 9be38c3..0000000 --- a/src/pages/profile/components/CourseList/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import CourseList from './CourseList'; -import CourseItem from './CourseItem'; - -export { CourseList, CourseItem };