From 66f091cc311795035bed2397d128630655fb5e5b Mon Sep 17 00:00:00 2001 From: Abin Date: Mon, 11 Sep 2023 00:17:54 +0530 Subject: [PATCH] intro part removed need to fix it --- .../pages/course-pages/discussion-list.tsx | 2 +- .../pages/course-pages/discussion-page.tsx | 8 ++-- .../pages/course-pages/quizzes-page.tsx | 4 +- .../pages/course-pages/video-player.tsx | 4 +- .../pages/course-pages/view-course.tsx | 4 +- .../pages/course-pages/watch-lesson.tsx | 41 ++++++++++++++----- client/src/types/course.ts | 6 +++ server/src/app/usecases/course/listCourse.ts | 8 ++++ .../repositories/courseReposMongoDb.ts | 2 +- server/src/types/courseInterface.ts | 1 + 10 files changed, 59 insertions(+), 21 deletions(-) diff --git a/client/src/components/pages/course-pages/discussion-list.tsx b/client/src/components/pages/course-pages/discussion-list.tsx index 75a39d1..d8f17b4 100644 --- a/client/src/components/pages/course-pages/discussion-list.tsx +++ b/client/src/components/pages/course-pages/discussion-list.tsx @@ -40,7 +40,7 @@ const MenuBar: React.FC<{ try { const response = await deleteDiscussions(discussionId); setUpdated(!updated); - toast.success(response.message, { + toast.success(response?.message, { position: toast.POSITION.BOTTOM_RIGHT, }); setOpen(!open); diff --git a/client/src/components/pages/course-pages/discussion-page.tsx b/client/src/components/pages/course-pages/discussion-page.tsx index 1661d3f..8a7a758 100644 --- a/client/src/components/pages/course-pages/discussion-page.tsx +++ b/client/src/components/pages/course-pages/discussion-page.tsx @@ -42,9 +42,9 @@ const Discussion: React.FC<{ lessonId: string }> = ({ lessonId }) => { } }; - const fetchDiscussions = async () => { + const fetchDiscussions = async (lessonId:string) => { try { - const response = await getDiscussionsByLesson(lessonId ?? ""); + const response = await getDiscussionsByLesson(lessonId); setDiscussions(response.data); } catch (error: any) { toast.error("Something went wrong", { @@ -53,7 +53,9 @@ const Discussion: React.FC<{ lessonId: string }> = ({ lessonId }) => { } }; useEffect(() => { - fetchDiscussions(); + if(lessonId){ + fetchDiscussions(lessonId); + } }, [updated]); const handleInputChange = (e: React.ChangeEvent) => { diff --git a/client/src/components/pages/course-pages/quizzes-page.tsx b/client/src/components/pages/course-pages/quizzes-page.tsx index bb51c34..91d0177 100644 --- a/client/src/components/pages/course-pages/quizzes-page.tsx +++ b/client/src/components/pages/course-pages/quizzes-page.tsx @@ -25,9 +25,9 @@ const Quizzes: React.FC<{ lessonId: string | undefined }> = ({ lessonId }) => { const fetchQuizzes = async (lessonId: string) => { try { const response = await getQuizzesByLesson(lessonId); - setQuizzes(response.data.questions); + setQuizzes(response?.data?.questions); } catch (error: any) { - toast.error(error.data.message, { + toast.error(error?.data?.message, { position: toast.POSITION.BOTTOM_RIGHT, }); } diff --git a/client/src/components/pages/course-pages/video-player.tsx b/client/src/components/pages/course-pages/video-player.tsx index 98b2b7c..45f54c9 100644 --- a/client/src/components/pages/course-pages/video-player.tsx +++ b/client/src/components/pages/course-pages/video-player.tsx @@ -6,7 +6,7 @@ import {useParams,useNavigate} from "react-router-dom"; interface VideoPlayerProps { videoKey: string | null; - isCoursePurchased: boolean; + isCoursePurchased: boolean|null; } const VideoPlayer: React.FC = ({ @@ -21,7 +21,7 @@ const VideoPlayer: React.FC = ({ const handleClick = ()=>{ navigate(`/courses/${courseId}`) } - + console.log(`https://d2vf4943yf4h7g.cloudfront.net/${videoKey}`) useEffect(() => { let player: any | undefined; const initializePlayer = () => { diff --git a/client/src/components/pages/course-pages/view-course.tsx b/client/src/components/pages/course-pages/view-course.tsx index 0861d84..be582af 100644 --- a/client/src/components/pages/course-pages/view-course.tsx +++ b/client/src/components/pages/course-pages/view-course.tsx @@ -210,12 +210,12 @@ const ViewCourseStudent: React.FC = () => { )} - + {/*
  • Introduction video
  • - + */} )} diff --git a/client/src/components/pages/course-pages/watch-lesson.tsx b/client/src/components/pages/course-pages/watch-lesson.tsx index 23d3ff5..aaafa33 100644 --- a/client/src/components/pages/course-pages/watch-lesson.tsx +++ b/client/src/components/pages/course-pages/watch-lesson.tsx @@ -3,7 +3,7 @@ import VideoPlayer from "./video-player"; import AboutLesson from "./about-lesson"; import Quizzes from "./quizzes-page"; import Discussion from "./discussion-page"; -import { useParams } from "react-router-dom"; +import { useParams, useLocation } from "react-router-dom"; import { toast } from "react-toastify"; import { getLessonById } from "../../../api/endpoints/course/lesson"; import { getLessonsByCourse } from "../../../api/endpoints/course/lesson"; @@ -24,6 +24,7 @@ const WatchLessons: React.FC = () => { const [allLessons, setAllLessons] = useState>([]); const [videoKey, setVideoKey] = useState(null); const { lessonId } = useParams(); + const location = useLocation(); const [currentLessonId, setCurrentLessonId] = useState( lessonId ); @@ -33,9 +34,10 @@ const WatchLessons: React.FC = () => { let isCoursePurchased = false; if (currentCourse) { - isCoursePurchased = currentCourse.coursesEnrolled.includes(studentId) + isCoursePurchased = currentCourse.coursesEnrolled.includes(studentId); } - + console.log(currentCourse) + console.log(currentCourse?.introduction.key) const handleItemClick = (index: number) => { setSelectedItemIndex(index); @@ -45,13 +47,13 @@ const WatchLessons: React.FC = () => { try { setIsLoadingAllLessons(true); const response = await getLessonsByCourse(courseId); - setAllLessons(response.data); + setAllLessons(response?.data); setTimeout(() => { setIsLoadingAllLessons(false); }, 3000); } catch (error: any) { setIsLoadingAllLessons(false); - toast.error(error.data.message, { + toast.error(error?.data?.message, { position: toast.POSITION.BOTTOM_RIGHT, }); } @@ -60,8 +62,8 @@ const WatchLessons: React.FC = () => { try { setIsLoadingLesson(true); const response = await getLessonById(lessonId); - setLesson(response.data); - const key = response.data.media.find( + setLesson(response?.data); + const key = response?.data?.media.find( (media: Media) => media.name === "lessonVideo" )?.key; setVideoKey(key); @@ -70,7 +72,7 @@ const WatchLessons: React.FC = () => { }, 2000); } catch (error: any) { setIsLoadingLesson(false); - toast.error(error.data.message, { + toast.error(error?.data?.message, { position: toast.POSITION.BOTTOM_RIGHT, }); } @@ -113,8 +115,8 @@ const WatchLessons: React.FC = () => {
    + isCoursePurchased={currentCourse && currentCourse.isPaid ? isCoursePurchased : true} + />
      @@ -168,6 +170,25 @@ const WatchLessons: React.FC = () => { Lessons
        + {/*
      • { + setCurrentLessonId(currentCourse?._id); + setVideoKey(currentCourse?.introduction?.key??"") + }} + className={`p-6 border-b-2 flex items-center cursor-pointer + ${ + currentCourse?._id === currentLessonId + ? "bg-gray-200 hover:bg-gray-200" + : "hover:bg-gray-100" + } + `} + > + + + Episode 0{0} - Introduction to the course + +
      • */} + {allLessons.map((lesson, index) => (
      • { const getCourseById = async (courseId: string) => { const course: CourseInterface | null = await Course.findOne({ _id: new mongoose.Types.ObjectId(courseId) - }); + }).lean() return course; }; diff --git a/server/src/types/courseInterface.ts b/server/src/types/courseInterface.ts index bbae388..b1701f1 100644 --- a/server/src/types/courseInterface.ts +++ b/server/src/types/courseInterface.ts @@ -28,6 +28,7 @@ export interface AddCourseInfoInterface { export interface CourseInterface extends AddCourseInfoInterface { coursesEnrolled:Array, thumbnailUrl:string, + introductionUrl:string, guidelinesUrl:string; }