forked from thehashton/curiouscourses
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7db50aa
commit 0976622
Showing
17 changed files
with
301 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.CourseList { | ||
padding: 0 !important; // overriding MUI | ||
max-height: 30rem; | ||
overflow: auto; | ||
} | ||
|
||
.lessonNavigation { | ||
min-width: 25rem; | ||
} | ||
|
||
.listItem { | ||
display: flex; | ||
align-items: center; | ||
margin-right: 0.25rem !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import scss from "./CourseList.module.scss"; | ||
import { LessonType } from "@/app/courses/course.types"; | ||
import { List, ListItemButton, ListItemText, Typography } from "@mui/material"; | ||
import SlowMotionVideoIcon from "@mui/icons-material/SlowMotionVideo"; | ||
import { useSearchParams } from "next/navigation"; | ||
import { useTheme } from "@mui/material/styles"; | ||
|
||
export type CourseListProps = { | ||
lessons: LessonType[]; | ||
lessonAmount: number; | ||
courseId: number; | ||
}; | ||
|
||
const CourseList = (props: CourseListProps) => { | ||
const { lessons, lessonAmount, courseId } = props; | ||
const [selectedLessonId, setSelectedLessonId] = useState<number | null>(null); | ||
const searchParams = useSearchParams(); | ||
const lessonParamId = searchParams.get("lessonId"); | ||
const theme = useTheme(); // Get the MUI theme | ||
|
||
useEffect(() => { | ||
// Checks and updates selectedLessonId when lessonParamId changes on page load | ||
setSelectedLessonId(lessonParamId ? parseInt(lessonParamId, 10) : 1); | ||
}, [lessonParamId]); | ||
|
||
const handleLessonClick = (lessonId: number) => { | ||
const lessonName = lessons[lessonId - 1]?.attributes.title; | ||
const formattedLessonName = lessonName?.replace(/\s+/g, ""); | ||
const newUrl = `/courses/${courseId}?lessonId=${lessonId}&lessonName=${formattedLessonName}`; | ||
window.history.replaceState(null, "", newUrl); | ||
setSelectedLessonId(lessonId); | ||
window.location.reload(); | ||
}; | ||
|
||
return ( | ||
<nav className={scss.lessonNavigation}> | ||
<List | ||
className={scss.CourseList} | ||
sx={{ | ||
overflowY: "scroll", | ||
"&::-webkit-scrollbar": { | ||
width: "8px", | ||
}, | ||
"&::-webkit-scrollbar-thumb": { | ||
backgroundColor: theme.palette.primary.main, | ||
borderRadius: "4px", | ||
}, | ||
"&::-webkit-scrollbar-track": { | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
}} | ||
> | ||
{lessons?.slice(0, lessonAmount).map((lesson: any, id: number) => ( | ||
<ListItemButton | ||
key={lesson.id} | ||
className={scss.listItem} | ||
style={{ | ||
backgroundColor: | ||
selectedLessonId === lesson.id | ||
? theme.palette.primary.main | ||
: "transparent", | ||
}} | ||
component="a" | ||
onClick={() => handleLessonClick(lesson.id)} | ||
> | ||
<div style={{ textAlign: "center" }}> | ||
<SlowMotionVideoIcon fontSize="large" /> | ||
<Typography fontSize={"small"}> | ||
{lesson.attributes.duration} | ||
</Typography> | ||
</div> | ||
<div style={{ marginLeft: "1rem" }}> | ||
<ListItemText | ||
style={{ margin: "0.5rem 0" }} | ||
primary={`${id + 1}. ${lesson.attributes.title}`} | ||
secondary={lesson.attributes.description} | ||
/> | ||
</div> | ||
</ListItemButton> | ||
))} | ||
</List> | ||
</nav> | ||
); | ||
}; | ||
|
||
export default CourseList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./CourseList"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.CoursePlayer { | ||
display: flex; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import scss from "./CoursePlayer.module.scss"; | ||
import PsychologyAltIcon from "@mui/icons-material/PsychologyAlt"; | ||
import { Paper, Typography } from "@mui/material"; | ||
import { LessonType } from "@/app/courses/course.types"; | ||
import { useSearchParams } from "next/navigation"; | ||
|
||
export type CoursePlayerProps = { | ||
lessons: LessonType[]; | ||
lessonVideoUrl: string; | ||
}; | ||
|
||
const CoursePlayer = (props: CoursePlayerProps) => { | ||
const { lessons, lessonVideoUrl } = props; | ||
|
||
const [selectedLessonId, setSelectedLessonId] = useState<number | null>(null); | ||
const searchParams = useSearchParams(); | ||
const lessonParamId = searchParams.get("lessonId"); | ||
|
||
useEffect(() => { | ||
// Checks and updates selectedLessonId when lessonParamId changes on page load | ||
setSelectedLessonId(lessonParamId ? parseInt(lessonParamId, 10) : null); | ||
}, [lessonParamId]); | ||
|
||
return ( | ||
<Paper | ||
className={scss.CoursePlayer} | ||
sx={{ | ||
display: "flex", | ||
width: "100%", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
minHeight: "30rem", | ||
maxHeight: "30rem", | ||
}} | ||
> | ||
{lessons?.length == 0 || undefined ? ( | ||
<div style={{ display: "block", textAlign: "center" }}> | ||
<PsychologyAltIcon | ||
color={"error"} | ||
style={{ fontSize: "5rem" }} | ||
></PsychologyAltIcon> | ||
<Typography> | ||
Oops! There are currently no lessons on this course. | ||
</Typography> | ||
</div> | ||
) : ( | ||
<iframe | ||
width="100%" | ||
height="480" | ||
src={lessonVideoUrl} | ||
frameBorder="0" | ||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" | ||
allowFullScreen | ||
title="Embedded youtube" | ||
/> | ||
)} | ||
</Paper> | ||
); | ||
}; | ||
|
||
export default CoursePlayer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./CoursePlayer"; |
Oops, something went wrong.