Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/components/core/ViewCourse/VideoDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
22 changes: 15 additions & 7 deletions src/pages/ViewCourse.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Comment on lines +25 to +31
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Type inconsistency: setEntireCourseData([]) should be an object, not an array.

courseEntireData is used as an object elsewhere (e.g., courseEntireData?.thumbnail in VideoDetails.jsx line 47). Dispatching an empty array [] is semantically incorrect - it works due to optional chaining but misrepresents the expected type.

🛠️ Suggested fix
      if (!courseData?.courseDetails) {
        dispatch(setCourseSectionData([]))
-       dispatch(setEntireCourseData([]))
+       dispatch(setEntireCourseData({}))
        dispatch(setCompletedLectures([]))
        dispatch(setTotalNoOfLectures(0))
        return
      }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!courseData?.courseDetails) {
dispatch(setCourseSectionData([]))
dispatch(setEntireCourseData([]))
dispatch(setCompletedLectures([]))
dispatch(setTotalNoOfLectures(0))
return
}
if (!courseData?.courseDetails) {
dispatch(setCourseSectionData([]))
dispatch(setEntireCourseData({}))
dispatch(setCompletedLectures([]))
dispatch(setTotalNoOfLectures(0))
return
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/ViewCourse.jsx` around lines 25 - 31, The reset branch wrongly
dispatches setEntireCourseData([]) as an array while courseEntireData is
expected to be an object (e.g., accessed as courseEntireData?.thumbnail in
VideoDetails.jsx); change the dispatch to setEntireCourseData({}) so the cleared
state has the correct object shape, leaving other resets
(setCourseSectionData([]), setCompletedLectures([]), setTotalNoOfLectures(0))
unchanged.


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))
})()
Expand Down