diff --git a/app/entities/course-card.tsx b/app/entities/course-card.tsx index 8d5b7cd..7d30fd3 100644 --- a/app/entities/course-card.tsx +++ b/app/entities/course-card.tsx @@ -14,7 +14,7 @@ interface Props { export function CourseCard({ id, picturePath, name, price, rating, isBought, isForEdit }: Props) { return ( - +
{item.elementName}
diff --git a/app/redux/slices/author.ts b/app/redux/slices/author.ts index 82dbb73..003055e 100644 --- a/app/redux/slices/author.ts +++ b/app/redux/slices/author.ts @@ -1,5 +1,4 @@ import { createSlice, createAsyncThunk } from '@reduxjs/toolkit' -import moment from 'moment' import instance from '~/axios' export const fetchAuthor = createAsyncThunk( diff --git a/app/redux/slices/lesson.ts b/app/redux/slices/lesson.ts new file mode 100644 index 0000000..ddffa75 --- /dev/null +++ b/app/redux/slices/lesson.ts @@ -0,0 +1,45 @@ +import { createSlice, createAsyncThunk } from '@reduxjs/toolkit' +import instance from '~/axios' + +export const fetchLesson = createAsyncThunk( + 'lesson/fetchLesson', + async (params: any) => { + const { data } = await instance.post('/Lesson/GetLessonFromCourseItem', params) + + return data + } +) + +const initialState = { + lesson: { + data: null, + isError: false, + status: 'loading', + }, +} + +const lessonSlice = createSlice({ + name: 'lesson', + initialState, + reducers: {}, + extraReducers: builder => { + builder.addCase(fetchLesson.pending, (state, action) => { + state.lesson.status = 'loading' + + // @ts-ignore + state.lesson.data = null + }) + builder.addCase(fetchLesson.fulfilled, (state, action) => { + state.lesson.status = 'loaded' + state.lesson.data = action.payload + }) + builder.addCase(fetchLesson.rejected, (state, action) => { + state.lesson.status = 'error' + + // @ts-ignore + state.lesson.data = null + }) + }, +}) + +export const lessonItemReducer = lessonSlice.reducer diff --git a/app/redux/store.ts b/app/redux/store.ts index a919eea..8eb0839 100644 --- a/app/redux/store.ts +++ b/app/redux/store.ts @@ -4,6 +4,7 @@ import { courseReducer } from "./slices/courses"; import { userReducer } from "./slices/user"; import { courseItemReducer } from "./slices/course"; import { authorReducer } from "./slices/author"; +import { lessonItemReducer } from "./slices/lesson"; const store = configureStore({ reducer: { @@ -12,6 +13,7 @@ const store = configureStore({ auth: authReducer, user: userReducer, author: authorReducer, + lesson: lessonItemReducer, }, }); diff --git a/app/routes/courses.$course.tsx b/app/routes/courses.$course.tsx index 32a40e4..0c3d311 100644 --- a/app/routes/courses.$course.tsx +++ b/app/routes/courses.$course.tsx @@ -9,7 +9,6 @@ import { ListElement } from '~/features' import { CourseElement } from '~/features/course-element' import { fetchAuthor } from '~/redux/slices/author' import { fetchCourse } from '~/redux/slices/courses' -import { fetchUser } from '~/redux/slices/user' import { FilledButton, Header2, Header3, Header4, Text } from '~/shared' export default function Course() { @@ -27,6 +26,8 @@ export default function Course() { formData.append('CourseID', params.course as string) formData.append('UserID', window.localStorage.getItem('userId') as string) dispatch(fetchCourse(formData)) + + window.localStorage.getItem('lectureID') }, []) useEffect(() => { diff --git a/app/routes/learn.$course.tsx b/app/routes/learn.$course.tsx new file mode 100644 index 0000000..69d67d7 --- /dev/null +++ b/app/routes/learn.$course.tsx @@ -0,0 +1,120 @@ +import type { ThunkDispatch } from '@reduxjs/toolkit' +import { useParams } from '@remix-run/react' +import { Spinner } from 'flowbite-react' +import { useEffect, useState } from 'react' +import { useDispatch, useSelector } from 'react-redux' +import { CourseElement } from '~/features/course-element' +import { fetchAuthor } from '~/redux/slices/author' +import { fetchFullCourse } from '~/redux/slices/course' +import { Header2, Header3, Header4, Text } from '~/shared' + +export default function Course() { + const params = useParams() + + const dispatch = useDispatch