From 6c12ee17f5ac950fc79ba1bc69ebbc6e1970677c Mon Sep 17 00:00:00 2001 From: swve Date: Tue, 15 Nov 2022 00:14:14 +0100 Subject: [PATCH] feat: improve course page --- .../course/[courseid]/edit/index.tsx | 6 +- .../[courseid]/element/[elementid]/index.tsx | 22 +++- .../org/[orgslug]/course/[courseid]/index.tsx | 113 +++++++++++++++--- front/services/courses/courses.ts | 19 ++- 4 files changed, 138 insertions(+), 22 deletions(-) diff --git a/front/pages/org/[orgslug]/course/[courseid]/edit/index.tsx b/front/pages/org/[orgslug]/course/[courseid]/edit/index.tsx index ba9adc3f..50f0e1d2 100644 --- a/front/pages/org/[orgslug]/course/[courseid]/edit/index.tsx +++ b/front/pages/org/[orgslug]/course/[courseid]/edit/index.tsx @@ -66,16 +66,16 @@ function CourseEdit() { // Submit new chapter const submitChapter = async (chapter: any) => { await createChapter(chapter, courseid); - getCourseChapters(); + await getCourseChapters(); setNewChapterModal(false); }; // Submit new element const submitElement = async (element: any) => { console.log("submitElement", element); - updateChaptersMetadata(courseid, data); + await updateChaptersMetadata(courseid, data); await createElement(element, element.chapterId); - getCourseChapters(); + await getCourseChapters(); setNewElementModal(false); }; diff --git a/front/pages/org/[orgslug]/course/[courseid]/element/[elementid]/index.tsx b/front/pages/org/[orgslug]/course/[courseid]/element/[elementid]/index.tsx index 690a70f1..cbe3fdd9 100644 --- a/front/pages/org/[orgslug]/course/[courseid]/element/[elementid]/index.tsx +++ b/front/pages/org/[orgslug]/course/[courseid]/element/[elementid]/index.tsx @@ -31,9 +31,25 @@ function ElementPage() { const output = useMemo(() => { if (router.isReady) { - console.log("element", element.content); + console.log( "el",element.content); + + let content = Object.keys(element.content).length > 0 ? element.content : { + "type": "doc", + "content": [ + { + "type": "paragraph", + "content": [ + { + "type": "text", + "text": "Hello world, this is a example Canva ⚡️" + } + ] + } + ] + } + console.log("element", content); - return generateHTML(element.content, [Document, StarterKit, Paragraph, Text, Bold]); + return generateHTML(content, [Document, StarterKit, Paragraph, Text, Bold]); } }, [element.content]); @@ -44,7 +60,7 @@ function ElementPage() { ) : (

element

-

{element.name}

+

{element.name}


diff --git a/front/pages/org/[orgslug]/course/[courseid]/index.tsx b/front/pages/org/[orgslug]/course/[courseid]/index.tsx index 6fddd3c4..f4d96afc 100644 --- a/front/pages/org/[orgslug]/course/[courseid]/index.tsx +++ b/front/pages/org/[orgslug]/course/[courseid]/index.tsx @@ -1,25 +1,25 @@ +import { EyeOpenIcon, Pencil2Icon } from "@radix-ui/react-icons"; +import Link from "next/link"; import { useRouter } from "next/router"; import React from "react"; import styled from "styled-components"; import Layout from "../../../../../components/ui/Layout"; import { getAPIUrl, getBackendUrl } from "../../../../../services/config"; -import { getCourse } from "../../../../../services/courses/courses"; +import { getCourse, getCourseMetadata } from "../../../../../services/courses/courses"; import { getOrganizationContextInfo } from "../../../../../services/orgs"; const CourseIdPage = () => { const router = useRouter(); - const { courseid } = router.query; + const { courseid, orgslug } = router.query; const [isLoading, setIsLoading] = React.useState(true); const [courseInfo, setCourseInfo] = React.useState({}) as any; async function fetchCourseInfo() { - const course = await getCourse("course_" + courseid); + const course = await getCourseMetadata("course_" + courseid); setCourseInfo(course); - - - console.log("courseinfo" , courseInfo); + setIsLoading(false); } @@ -29,7 +29,7 @@ const CourseIdPage = () => { fetchCourseInfo(); } return () => {}; - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps }, [router.isReady]); return ( @@ -37,23 +37,82 @@ const CourseIdPage = () => { {isLoading ? (
Loading...
) : ( -
+

Course

-

{courseInfo.name}

- - - -
+

+ {courseInfo.course.name}{" "} + + +   + + {" "} +

+
+ + {courseInfo.chapters.map((chapter: any) => { + return ( + <> + {chapter.elements.map((element: any) => { + return ( + <> + + + + + {" "} + + ); + })} +      + + ); + })} + + + + + + +

Description

+

{courseInfo.course.description}

+ +

What you will learn

+

{courseInfo.course.learnings == ![] ? "no data" : courseInfo.course.learnings}

+ +

Course Lessons

+ + {courseInfo.chapters.map((chapter: any) => { + return ( + <> +

Chapter : {chapter.name}

+ {chapter.elements.map((element: any) => { + return ( + <> +

+ Element {element.name} + + +   + + {" "} +

+ + ); + })} +      + + ); + })} + )} ); }; -const CourseWrapper = styled.div` +const CourseThumbnailWrapper = styled.div` display: flex; img { - position: absolute; width: 794px; height: 224.28px; object-fit: cover; @@ -65,5 +124,29 @@ const CourseWrapper = styled.div` border-radius: 7px; } `; +const CoursePageLayout = styled.div` + margin-left: 40px; + margin-right: 40px; +`; + +const ChaptersWrapper = styled.div` + display: flex; +`; +const ChapterIndicator = styled.div` + border-radius: 20px; + height: 5px; + background: #151515; + border-radius: 3px; + width: 40px; + background-color: black; + margin: 10px; + margin-left: 0px; + transition: all 0.2s ease; + + &:hover { + width: 50px; + cursor: pointer; + } +`; export default CourseIdPage; diff --git a/front/services/courses/courses.ts b/front/services/courses/courses.ts index bed9ba75..2bd0861e 100644 --- a/front/services/courses/courses.ts +++ b/front/services/courses/courses.ts @@ -15,7 +15,7 @@ export async function getOrgCourses(org_id: number) { .catch((error) => console.log("error", error)); } -export async function getCourse(course_id: any) { +export async function getCourse(course_id: string) { const HeadersConfig = new Headers({ "Content-Type": "application/json" }); const requestOptions: any = { @@ -31,6 +31,23 @@ export async function getCourse(course_id: any) { .catch((error) => console.log("error", error)); } +export async function getCourseMetadata(course_id: string) { + const HeadersConfig = new Headers({ "Content-Type": "application/json" }); + + const requestOptions: any = { + method: "GET", + headers: HeadersConfig, + redirect: "follow", + credentials: "include", + }; + + // todo : add course id to url + return fetch(`${getAPIUrl()}courses/meta/${course_id}`, requestOptions) + .then((result) => result.json()) + .catch((error) => console.log("error", error)); + +} + export async function createNewCourse(org_id: string, course_body: any, thumbnail: any) { const HeadersConfig = new Headers();