diff --git a/src/components/core/ViewCourse/VideoDetails.jsx b/src/components/core/ViewCourse/VideoDetails.jsx index a03cf91..4e12665 100644 --- a/src/components/core/ViewCourse/VideoDetails.jsx +++ b/src/components/core/ViewCourse/VideoDetails.jsx @@ -20,15 +20,17 @@ const VideoDetails = () => { const { courseSectionData, courseEntireData, completedLectures } = useSelector((state) => state.viewCourse) - const [videoData, setVideoData] = useState([]) + const [videoData, setVideoData] = useState(null) const [previewSource, setPreviewSource] = useState("") const [videoEnded, setVideoEnded] = useState(false) const [loading, setLoading] = useState(false) useEffect(() => { - const load=async () => { - console.log("Checkicickkc"); - if (!courseSectionData.length) return + const load = async () => { + if (!courseSectionData.length) { + setVideoData(null) + return + } if (!courseId && !sectionId && !subSectionId) { navigate(`/dashboard/enrolled-courses`) } else { @@ -37,16 +39,17 @@ const VideoDetails = () => { (course) => course._id === sectionId ) // console.log("filteredData", filteredData) - const filteredVideoData = filteredData?.[0]?.subSection.filter( + const filteredVideoData = filteredData?.[0]?.subSection?.find( (data) => data._id === subSectionId ) - console.log("filteredVideoData", filteredVideoData) - setVideoData(filteredVideoData[0]) - setPreviewSource(courseEntireData.thumbnail) + + setVideoData(filteredVideoData ?? null) + setPreviewSource(courseEntireData?.thumbnail ?? "") setVideoEnded(false) } - }; - load(); + } + + load() }, [courseSectionData, courseEntireData, location.pathname]) // check if the lecture is the first video of the course diff --git a/src/pages/ViewCourse.jsx b/src/pages/ViewCourse.jsx index 6bb58ea..c2c78c7 100644 --- a/src/pages/ViewCourse.jsx +++ b/src/pages/ViewCourse.jsx @@ -20,15 +20,23 @@ export default function ViewCourse() { useEffect(() => { ;(async () => { - console.log("Course ID here... ", token, courseId) - const courseData = await getFullCourseDetails({courseId, token}) - // console.log("Course Data here... ", courseData) - dispatch(setCourseSectionData(courseData.courseDetails.courseContent)) + const courseData = await getFullCourseDetails({ courseId, token }) + + if (!courseData?.courseDetails) { + dispatch(setCourseSectionData([])) + dispatch(setEntireCourseData([])) + dispatch(setCompletedLectures([])) + dispatch(setTotalNoOfLectures(0)) + return + } + + dispatch(setCourseSectionData(courseData.courseDetails.courseContent ?? [])) dispatch(setEntireCourseData(courseData.courseDetails)) - dispatch(setCompletedLectures(courseData.completedVideos)) + dispatch(setCompletedLectures(courseData.completedVideos ?? [])) + let lectures = 0 - courseData?.courseDetails?.courseContent?.forEach((sec) => { - lectures += sec.subSection.length + courseData.courseDetails.courseContent?.forEach((sec) => { + lectures += sec.subSection?.length ?? 0 }) dispatch(setTotalNoOfLectures(lectures)) })()