diff --git a/src/components/Player.tsx b/src/components/Player.tsx index a6cf6b37b1a4ae3693fbe0473cac2b1c0a50d1ba..d633aca3dfe08ee3e332f1eaf4fa85eaf08d674d 100644 --- a/src/components/Player.tsx +++ b/src/components/Player.tsx @@ -609,10 +609,14 @@ function Chapters({ chapters, seekTo }: { chapters?: chapter[]; seekTo: (time: n function VideoSuggestions({ course, lecture }: { course: course; lecture: lecture }) { const { language } = useLanguage(); // find previous and next lecture - const prevLecture = course.lectures?.findLast( + const sortedLectures = course.lectures?.sort((a, b) => { + // time looks like this: 2015-10-20T12:15:00 + return new Date(a.time).valueOf() - new Date(b.time).valueOf(); + }); + const prevLecture = sortedLectures?.findLast( (l) => new Date(l.time) < new Date(lecture.time) && (l.media_sources ?? []).length > 0, ); - const nextLecture = course.lectures?.find( + const nextLecture = sortedLectures?.find( (l) => new Date(l.time) > new Date(lecture.time) && (l.media_sources ?? []).length > 0, );