From 47b354db12ab6bc6899c78358e6f72eb8bc15551 Mon Sep 17 00:00:00 2001 From: swve Date: Mon, 28 Apr 2025 20:29:30 +0200 Subject: [PATCH] feat: course page changes --- .../(withmenu)/course/[courseuuid]/course.tsx | 360 +++++++++--------- 1 file changed, 185 insertions(+), 175 deletions(-) diff --git a/apps/web/app/orgs/[orgslug]/(withmenu)/course/[courseuuid]/course.tsx b/apps/web/app/orgs/[orgslug]/(withmenu)/course/[courseuuid]/course.tsx index 236415c3..41dfbbb1 100644 --- a/apps/web/app/orgs/[orgslug]/(withmenu)/course/[courseuuid]/course.tsx +++ b/apps/web/app/orgs/[orgslug]/(withmenu)/course/[courseuuid]/course.tsx @@ -60,6 +60,16 @@ const CourseClient = (props: any) => { useEffect(() => { getLearningTags() + + // Collapse chapters by default if more than 5 activities in total + if (course?.chapters) { + const totalActivities = course.chapters.reduce((sum: number, chapter: any) => sum + (chapter.activities?.length || 0), 0) + const defaultExpanded: {[key: string]: boolean} = {} + course.chapters.forEach((chapter: any) => { + defaultExpanded[chapter.chapter_uuid] = totalActivities <= 5 + }) + setExpandedChapters(defaultExpanded) + } }, [org, course]) const getActivityTypeLabel = (activityType: string) => { @@ -117,191 +127,52 @@ const CourseClient = (props: any) => { ) : ( <> -
+

Course

{course.name}

- {props.course?.thumbnail_image && org ? ( -
- ) : ( -
- )} - - - -
-
-

About

-
-

{course.about}

-
- - {learnings.length > 0 && learnings[0]?.text !== 'null' && ( -
-

- What you will learn -

-
- {learnings.map((learning: any) => { - // Handle both new format (object with text and emoji) and legacy format (string) - const learningText = typeof learning === 'string' ? learning : learning.text - const learningEmoji = typeof learning === 'string' ? null : learning.emoji - const learningId = typeof learning === 'string' ? learning : learning.id || learning.text - - if (!learningText) return null - - return ( -
-
- {learningEmoji ? ( - {learningEmoji} - ) : ( - - )} -
-

{learningText}

- {learning.link && ( - - Link to {learningText} - - - )} -
- ) - })} -
-
+
+
+ {props.course?.thumbnail_image && org ? ( +
+ ) : ( +
)} -

Course Lessons

-
- {course.chapters.map((chapter: any) => { - const isExpanded = expandedChapters[chapter.chapter_uuid] ?? true; // Default to expanded - return ( -
-
setExpandedChapters(prev => ({ - ...prev, - [chapter.chapter_uuid]: !isExpanded - }))} - > -

{chapter.name}

-
-

- {chapter.activities.length} Activities -

- - - -
-
-
-
- {chapter.activities.map((activity: any) => { - return ( -
-
-
-
- {isActivityDone(activity) ? ( -
- - -
- ) : ( -
- -
- )} -
- -
-

{activity.name}

- {isActivityCurrent(activity) && ( -
- Current -
- )} -
-
- {activity.activity_type === 'TYPE_DYNAMIC' && ( - - )} - {activity.activity_type === 'TYPE_VIDEO' && ( -
- -
- -
-
-
-
- ) - })} -
-
-
- ) - })} + {course?.trail?.runs?.find((run: any) => run.course_id == course.id) && ( + + )} + +
+
+

{course.about}

+
-
+ +
{/* Actions Box */} @@ -313,6 +184,145 @@ const CourseClient = (props: any) => {
+ + {learnings.length > 0 && learnings[0]?.text !== 'null' && ( +
+

What you will learn

+
+ {learnings.map((learning: any) => { + // Handle both new format (object with text and emoji) and legacy format (string) + const learningText = typeof learning === 'string' ? learning : learning.text + const learningEmoji = typeof learning === 'string' ? null : learning.emoji + const learningId = typeof learning === 'string' ? learning : learning.id || learning.text + + if (!learningText) return null + + return ( +
+
+ {learningEmoji ? ( + {learningEmoji} + ) : ( + + )} +
+

{learningText}

+ {learning.link && ( + + Link to {learningText} + + + )} +
+ ) + })} +
+
+ )} + +
+

Course Lessons

+
+ {course.chapters.map((chapter: any) => { + const isExpanded = expandedChapters[chapter.chapter_uuid] ?? true; // Default to expanded + return ( +
+
setExpandedChapters(prev => ({ + ...prev, + [chapter.chapter_uuid]: !isExpanded + }))} + > +

{chapter.name}

+
+

+ {chapter.activities.length} Activities +

+ + + +
+
+
+
+ {chapter.activities.map((activity: any) => { + return ( + +
+
+ {isActivityDone(activity) ? ( +
+ + +
+ ) : ( +
+ +
+ )} +
+
+
+

{activity.name}

+ {isActivityCurrent(activity) && ( +
+ Current +
+ )} +
+
+ {activity.activity_type === 'TYPE_DYNAMIC' && ( + + )} + {activity.activity_type === 'TYPE_VIDEO' && ( +
+
+
+ +
+
+ + ) + })} +
+
+
+ ) + })} +
+
{isMobile && (