Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intro part removed need to fix it #81

Merged
merged 1 commit into from
Sep 10, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions client/src/components/pages/course-pages/discussion-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand All @@ -53,7 +53,9 @@ const Discussion: React.FC<{ lessonId: string }> = ({ lessonId }) => {
}
};
useEffect(() => {
fetchDiscussions();
if(lessonId){
fetchDiscussions(lessonId);
}
}, [updated]);

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/pages/course-pages/quizzes-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/pages/course-pages/video-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<VideoPlayerProps> = ({
Expand All @@ -21,7 +21,7 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
const handleClick = ()=>{
navigate(`/courses/${courseId}`)
}

console.log(`https://d2vf4943yf4h7g.cloudfront.net/${videoKey}`)
useEffect(() => {
let player: any | undefined;
const initializePlayer = () => {
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/pages/course-pages/view-course.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ const ViewCourseStudent: React.FC = () => {
<PdfViewer pdfUrl={course?.guidelinesUrl ?? ""} />
)}

<Link to={"watch-lessons/1"}>
{/* <Link to={`watch-lessons/introduction`}>
<li className='p-6 border-b flex items-center cursor-pointer hover:bg-customBlueShade'>
<BiVideo className='mr-2 text-blue-500' />
<span className='flex-1'>Introduction video</span>
</li>
</Link>
</Link> */}
</ul>
</li>
)}
Expand Down
41 changes: 31 additions & 10 deletions client/src/components/pages/course-pages/watch-lesson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -24,6 +24,7 @@ const WatchLessons: React.FC = () => {
const [allLessons, setAllLessons] = useState<Array<ApiResponseLesson>>([]);
const [videoKey, setVideoKey] = useState<string | null>(null);
const { lessonId } = useParams();
const location = useLocation();
const [currentLessonId, setCurrentLessonId] = useState<string | undefined>(
lessonId
);
Expand All @@ -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);
Expand All @@ -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,
});
}
Expand All @@ -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);
Expand All @@ -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,
});
}
Expand Down Expand Up @@ -113,8 +115,8 @@ const WatchLessons: React.FC = () => {
<div className='h-3/4'>
<VideoPlayer
videoKey={videoKey}
isCoursePurchased={isCoursePurchased}
/>
isCoursePurchased={currentCourse && currentCourse.isPaid ? isCoursePurchased : true}
/>
</div>
<div className=''>
<ul className='flex p-3'>
Expand Down Expand Up @@ -168,6 +170,25 @@ const WatchLessons: React.FC = () => {
Lessons
</h1>
<ul>
{/* <li
onClick={() => {
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"
}
`}
>
<BiVideo className='mr-2 text-blue-500' />
<span className='flex-1 text-sm font-light text-gray-700'>
Episode 0{0} - Introduction to the course
</span>
</li> */}

{allLessons.map((lesson, index) => (
<li
key={lesson._id}
Expand Down
6 changes: 6 additions & 0 deletions client/src/types/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface CourseInterface {
price: number;
about: string;
description: string;
introduction:Media;
syllabus: string[];
requirements: string[];
thumbnailUrl: string;
Expand All @@ -22,3 +23,8 @@ export interface CourseInterface {
__v: number;
}

export interface Media{
key: string
name: string
_id: string
}
8 changes: 8 additions & 0 deletions server/src/app/usecases/course/listCourse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export const getCourseByIdU = async (
const course: CourseInterface | null = await courseDbRepository.getCourseById(
courseId
);
// if(course){
// course.introductionUrl=" "
// }
if (course) {
if (course.thumbnail) {
const thumbnail = await cloudService.getFile(course.thumbnail.key);
Expand All @@ -44,6 +47,11 @@ export const getCourseByIdU = async (
const guidelines = await cloudService.getFile(course.guidelines.key);
course.guidelinesUrl = guidelines;
}
// if(course.introduction){
// const introduction = await cloudService.getFile(course.introduction.key)
// console.log(introduction)
// course.introductionUrl = introduction
// }
}
return course;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const courseRepositoryMongodb = () => {
const getCourseById = async (courseId: string) => {
const course: CourseInterface | null = await Course.findOne({
_id: new mongoose.Types.ObjectId(courseId)
});
}).lean()
return course;
};

Expand Down
1 change: 1 addition & 0 deletions server/src/types/courseInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface AddCourseInfoInterface {
export interface CourseInterface extends AddCourseInfoInterface {
coursesEnrolled:Array<string>,
thumbnailUrl:string,
introductionUrl:string,
guidelinesUrl:string;

}
Expand Down
Loading