diff --git a/src/components/PageElements/index.tsx b/src/components/PageElements/index.tsx index b5cf7c3..90a1d17 100644 --- a/src/components/PageElements/index.tsx +++ b/src/components/PageElements/index.tsx @@ -22,7 +22,11 @@ export const PageHeading: React.FC = props => { ); }; -export const PageContent: React.FC = props => {props.children}; +export const PageContent: React.FC = props => ( + + {props.children} + +); export const PageFooter: React.FC = props => ( diff --git a/src/hooks/queries/lesson/useFetchLesson.ts b/src/hooks/queries/lesson/useFetchLesson.ts new file mode 100644 index 0000000..7c2f27b --- /dev/null +++ b/src/hooks/queries/lesson/useFetchLesson.ts @@ -0,0 +1,21 @@ +import useAsync from '@educt/hooks/useAsync'; +import { ILesson } from '@educt/interfaces'; +import { LessonServiceInstance } from '@educt/services'; +import { useEffect } from 'react'; + +const useFetchLesson = (id: string) => { + const fetch = async (id: string) => { + const { data } = await LessonServiceInstance.fetchLessonById(id); + return data; + }; + + const { execute: fetchLessonById, ...state } = useAsync>(fetch); + + useEffect(() => { + fetchLessonById(id); + }, [id]); + + return { ...state }; +}; + +export { useFetchLesson }; diff --git a/src/pages/course/course.tsx b/src/pages/course/course.tsx index 654eb64..a35d6a1 100644 --- a/src/pages/course/course.tsx +++ b/src/pages/course/course.tsx @@ -124,9 +124,9 @@ const CoursePage: React.FC = () => { - + - + Content diff --git a/src/pages/course/index.tsx b/src/pages/course/index.tsx index 79d0d75..8f9b3f0 100644 --- a/src/pages/course/index.tsx +++ b/src/pages/course/index.tsx @@ -188,10 +188,7 @@ export const LessonItem: React.FC = props => { display={'flex'} fontSize={'sm'} justifyContent={'space-between'} - pl='5' - pr='5' - pb='5' - pt='5' + p='5' minH='85px' borderRadius={'xl'} transition={'ease-in-out .1s'} diff --git a/src/pages/lesson/lesson.tsx b/src/pages/lesson/lesson.tsx index 83adcfa..053cee2 100644 --- a/src/pages/lesson/lesson.tsx +++ b/src/pages/lesson/lesson.tsx @@ -1,5 +1,6 @@ import React from 'react'; -import { Box, Heading } from '@chakra-ui/react'; +import moment from 'moment'; +import { Flex, Box, Button, Divider, Heading, Text, Grid, GridItem, Stack, Icon, IconButton } from '@chakra-ui/react'; /** * Types @@ -9,18 +10,98 @@ import { IPageProps } from '@educt/interfaces'; /** * Hooks */ -import { useParams } from 'react-router-dom'; +import { Redirect, useParams } from 'react-router-dom'; +import { PageContent, PageHeading, PageWrapper } from '@educt/components/PageElements'; +import { useFetchLesson } from '@educt/hooks/queries/lesson/useFetchLesson'; +import LoadingPage from '@educt/components/LoadingPage'; +import { MdCheckCircle, MdOutlineFilePresent, MdSkipNext, MdSkipPrevious } from 'react-icons/md'; /** * Lesson Page */ const LessonPage: React.FC = () => { const { id } = useParams<{ id: string }>(); + const { error, data: lesson, isLoading } = useFetchLesson(id); + + if (error?.response?.status === 404) { + return ; + } + + if (!lesson || isLoading) return ; return ( - - Lesson {id} - + + + + ~{moment.duration(lesson.duration, 'minutes').humanize()} + + + + + + + + + + + } size='sm' mr='2' /> + + + + + + Description + + {lesson.description} + + + + + + + + {Array(50) + .fill(1) + .map((n, i) => ( + + + + + Lesson {i + 1} + + + Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel, eaque. + + + + ))} + + + + + + + Materials + + + {[1, 2, 3].map(n => ( + + + + lesson-1_sourse-code.zip
+ 190kB +
+
+ ))} +
+
+
+
+
+
+
); }; diff --git a/src/services/LessonService.ts b/src/services/LessonService.ts index 9c84e83..1bc4388 100644 --- a/src/services/LessonService.ts +++ b/src/services/LessonService.ts @@ -9,6 +9,17 @@ class LessonService { this.api = api; } + /** + * Get lesson by id + * + * @param id Lesson id + * @returns Lesson + */ + public async fetchLessonById(id: string): Promise> { + const result = await this.api.get(`/v1/lessons/${id}`); + return result.data; + } + /** * Delete lesson by id *