From 63082e50c22cb76e9619f5a63c221417b4b7816c Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Fri, 17 Dec 2021 21:55:28 +0300 Subject: [PATCH] feat: added layout --- src/hooks/queries/course/useFetchCourse.ts | 4 +- src/index.tsx | 3 +- src/pages/404/404.tsx | 2 +- src/pages/auth/auth.tsx | 7 +- .../auth/components/AuthForm/AuthForm.tsx | 2 +- src/pages/course/course.tsx | 221 ++++++++++++++++++ src/routes.config.ts | 8 + src/services/CourseService.ts | 4 +- src/theme.ts | 24 ++ 9 files changed, 261 insertions(+), 14 deletions(-) create mode 100644 src/pages/course/course.tsx create mode 100644 src/theme.ts diff --git a/src/hooks/queries/course/useFetchCourse.ts b/src/hooks/queries/course/useFetchCourse.ts index 7f00f53..636ad5a 100644 --- a/src/hooks/queries/course/useFetchCourse.ts +++ b/src/hooks/queries/course/useFetchCourse.ts @@ -10,15 +10,13 @@ import { CourseServiceInstance } from '@educt/services'; import { useEffect } from 'react'; import useAsync from '../../useAsync'; -type CourseResultDataType = Omit; - const useFetchCourse = (id: string) => { const fetch = async (id: string) => { const { data } = await CourseServiceInstance.fetchById(id); return data; }; - const { execute: fetchCourseById, ...state } = useAsync>(fetch); + const { execute: fetchCourseById, ...state } = useAsync>(fetch); useEffect(() => { fetchCourseById(id); diff --git a/src/index.tsx b/src/index.tsx index c2f00a8..085d093 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,7 +1,8 @@ -import { ChakraProvider, ColorModeScript, theme } from '@chakra-ui/react'; import * as React from 'react'; import ReactDOM from 'react-dom'; +import { ChakraProvider, ColorModeScript } from '@chakra-ui/react'; import App from './App'; +import { theme } from './theme'; import { RootStoreProvider } from './providers'; ReactDOM.render( diff --git a/src/pages/404/404.tsx b/src/pages/404/404.tsx index 53d58a9..4dc3dc3 100644 --- a/src/pages/404/404.tsx +++ b/src/pages/404/404.tsx @@ -21,7 +21,7 @@ const NotFoundPage: React.FC = ({ title }) => { useEffect(() => { toast({ title: `Page not found`, duration: 10000, isClosable: true, status: 'warning' }); - }); + }, []); return ( <> diff --git a/src/pages/auth/auth.tsx b/src/pages/auth/auth.tsx index e7f4288..44b7759 100644 --- a/src/pages/auth/auth.tsx +++ b/src/pages/auth/auth.tsx @@ -41,11 +41,8 @@ const AuthPage: React.FC = ({ title }) => { {title} - - - - Login to your account - + + diff --git a/src/pages/auth/components/AuthForm/AuthForm.tsx b/src/pages/auth/components/AuthForm/AuthForm.tsx index 74186b2..60dd7e2 100644 --- a/src/pages/auth/components/AuthForm/AuthForm.tsx +++ b/src/pages/auth/components/AuthForm/AuthForm.tsx @@ -84,7 +84,7 @@ const AuthForm: React.FC = () => { + + + + + + + + + Last update: {new Date(course.updated_at).toLocaleDateString()} + + + + + + + + About + + + + + + + About this course + + {course.description} + + {course.students.length !== 0 ? ( + + + Students: + + + {course.students.map(student => ( + + ))} + + + ) : ( + + + 0 students + + + )} + + + + + + + + + + + What you'll learn. + + + Lorem, ipsum dolor sit amet consectetur adipisicing elit. Iste temporibus harum eos praesentium hic, + sunt corporis deserunt impedit natus consequuntur? + + + + + + + Content + + + {course.lessons_count} lessons + + + {course.lessons.length !== 0 ? ( + + {course.lessons.map(lesson => { + return ( + + + + + {lesson.title} + + + {moment.duration(lesson.duration).asMinutes()}min + + ); + })} + + ) : ( + + + There are no lessons here yet + + + )} + + + + + + + ); +}; + +export default CoursePage; diff --git a/src/routes.config.ts b/src/routes.config.ts index dc7357d..75b90ba 100644 --- a/src/routes.config.ts +++ b/src/routes.config.ts @@ -8,6 +8,7 @@ import AuthPage from '@educt/pages/auth/auth'; import NotFoundPage from '@educt/pages/404/404'; import CreateCoursePage from '@educt/pages/courses/create/create'; import CreateLessonPage from '@educt/pages/courses/create-lesson/create-lesson'; +import CoursePage from '@educt/pages/course/course'; import EditCoursePage from '@educt/pages/courses/edit/edit'; import ChangePasswordPage from '@educt/pages/profile/change-password/change-password'; import ChangeEmailPage from '@educt/pages/profile/change-email/change-email'; @@ -32,6 +33,13 @@ export const routes: IRouteOption[] = [ exact: true, isPrivate: true, }, + { + path: '/course/:id', + title: 'Course', + component: CoursePage, + isPrivate: true, + exact: true, + }, { path: '/courses', title: 'Courses', diff --git a/src/services/CourseService.ts b/src/services/CourseService.ts index 2078ad6..881a8f2 100644 --- a/src/services/CourseService.ts +++ b/src/services/CourseService.ts @@ -35,9 +35,7 @@ class CourseService { * @param id Course id * @returns Course */ - public async fetchById( - id: string - ): Promise>> { + public async fetchById(id: string): Promise> { const result = await this.api.get(`/v1/courses/${id}`); return result.data; } diff --git a/src/theme.ts b/src/theme.ts new file mode 100644 index 0000000..2af47ec --- /dev/null +++ b/src/theme.ts @@ -0,0 +1,24 @@ +import { extendTheme } from '@chakra-ui/react'; + +export const theme = extendTheme({ + styles: { + global: { + body: { + scrollbarWidth: 'thin', + scrollbarColor: '#000', + }, + '::-webkit-scrollbar': { + width: '5px', + height: '5px', + }, + '::-webkit-scrollbar-track': { + backgroundColor: 'gray.100', + borderRadius: '100px', + }, + '::-webkit-scrollbar-thumb': { + background: 'blue.600', + borderRadius: '100px', + }, + }, + }, +});