Skip to content

Commit 8a26d92

Browse files
authored
Merge pull request #289 from topcoder-platform/TCA-400_update-fcc-sidebar-behavior
TCA-400 - update behavior for fcc sidebar (course outline navigation)
2 parents 5f784fd + 0b30d96 commit 8a26d92

File tree

9 files changed

+122
-54
lines changed

9 files changed

+122
-54
lines changed

src-ts/tools/learn/course-certificate/certificate-view/certificate/certificate-bg-pattern/CertificateBgPattern.module.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
> div {
3232
position: absolute;
3333
top: 0;
34-
left: 0;
34+
left: -1px;
3535
width: 100%;
3636
height: 100%;
3737
z-index: 1;
@@ -42,7 +42,7 @@
4242
}
4343

4444
&:global(.wave-bg) {
45-
background: url('./wave-bg.png') -1px 0 repeat-y;
45+
background: url('./wave-bg.png') 0 0 repeat-y;
4646
background-size: 400px 116px;
4747
}
4848
}

src-ts/tools/learn/free-code-camp/FreeCodeCamp.module.scss

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,3 @@
4848
}
4949
}
5050
}
51-
52-
.course-outline-pane {
53-
position: absolute;
54-
left: 0;
55-
top: 0;
56-
bottom: 0;
57-
58-
@include ltemd {
59-
position: relative;
60-
top: auto;
61-
left: auto;
62-
bottom: auto;
63-
flex: 0 0 auto;
64-
}
65-
}
66-
67-
.course-outline-wrap {
68-
width: 406px;
69-
70-
@include ltemd {
71-
width: 100%;
72-
}
73-
}
74-
75-
.course-outline-title {
76-
@extend .body-main-bold;
77-
flex: 0 0 auto;
78-
margin-bottom: $space-xl;
79-
}

src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import {
1919
ProfileContextData,
2020
} from '../../../lib'
2121
import {
22-
CollapsiblePane,
23-
CourseOutline,
2422
CoursesProviderData,
2523
LearnLesson,
2624
LearnModule,
@@ -39,6 +37,7 @@ import {
3937
import { getCertificationCompletedPath, getCoursePath, getLessonPathFromModule } from '../learn.routes'
4038

4139
import { FccFrame } from './fcc-frame'
40+
import { FccSidebar } from './fcc-sidebar'
4241
import styles from './FreeCodeCamp.module.scss'
4342
import { TitleNav } from './title-nav'
4443

@@ -362,24 +361,13 @@ const FreeCodeCamp: FC<{}> = () => {
362361

363362
{lesson && (
364363
<div className={styles['main-wrap']}>
365-
<div className={styles['course-outline-pane']}>
366-
<CollapsiblePane
367-
title='Course Outline'
368-
onToggle={(isOpen) => isOpen && refetchProgress()}
369-
>
370-
<div className={styles['course-outline-wrap']}>
371-
<div className={styles['course-outline-title']}>
372-
{courseData?.title}
373-
</div>
374-
<CourseOutline
375-
course={courseData}
376-
ready={courseDataReady}
377-
currentStep={`${moduleParam}/${lessonParam}`}
378-
progress={certificateProgress}
379-
/>
380-
</div>
381-
</CollapsiblePane>
382-
</div>
364+
<FccSidebar
365+
courseData={courseData}
366+
courseDataReady={courseDataReady}
367+
currentStep={`${moduleParam}/${lessonParam}`}
368+
certificateProgress={certificateProgress}
369+
refetchProgress={refetchProgress}
370+
/>
383371

384372
<div className={styles['course-frame']}>
385373
<TitleNav
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@use '../../../../lib/styles/typography';
2+
@import '../../../../lib/styles/includes';
3+
4+
.course-outline-pane {
5+
position: absolute;
6+
left: 0;
7+
top: 0;
8+
bottom: 0;
9+
10+
@include ltemd {
11+
position: relative;
12+
top: auto;
13+
left: auto;
14+
bottom: auto;
15+
flex: 0 0 auto;
16+
}
17+
}
18+
19+
.course-outline-wrap {
20+
width: 406px;
21+
22+
@include ltemd {
23+
width: 100%;
24+
}
25+
}
26+
27+
.course-outline-title {
28+
@extend .body-main-bold;
29+
flex: 0 0 auto;
30+
margin-bottom: $space-xl;
31+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { FC, useState } from 'react'
2+
3+
import { CollapsiblePane, CourseOutline, LearnCourse, LearnUserCertificationProgress } from '../../learn-lib'
4+
5+
import styles from './FccSidebar.module.scss'
6+
7+
interface FccSidebarProps {
8+
certificateProgress?: LearnUserCertificationProgress
9+
courseData?: LearnCourse
10+
courseDataReady: boolean
11+
currentStep: string
12+
refetchProgress: () => void
13+
}
14+
15+
const FccSidebar: FC<FccSidebarProps> = (props: FccSidebarProps) => {
16+
const [isOpen, setIsOpen]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)
17+
18+
const handleToggle: (isOutlineOpen: boolean) => void = (isOutlineOpen: boolean) => {
19+
setIsOpen(isOutlineOpen)
20+
if (isOutlineOpen) {
21+
props.refetchProgress()
22+
}
23+
}
24+
25+
return (
26+
<div className={styles['course-outline-pane']}>
27+
<CollapsiblePane
28+
title='Course Outline'
29+
onToggle={handleToggle}
30+
isOpen={isOpen}
31+
>
32+
<div className={styles['course-outline-wrap']}>
33+
<div className={styles['course-outline-title']}>
34+
{props.courseData?.title}
35+
</div>
36+
<CourseOutline
37+
course={props.courseData}
38+
ready={props.courseDataReady}
39+
currentStep={props.currentStep}
40+
progress={props.certificateProgress}
41+
onItemNavigate={() => setIsOpen(false)}
42+
/>
43+
</div>
44+
</CollapsiblePane>
45+
</div>
46+
)
47+
}
48+
49+
export default FccSidebar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as FccSidebar } from './FccSidebar'

src-ts/tools/learn/learn-lib/collapsible-pane/CollapsiblePane.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import classNames from 'classnames'
22
import { noop } from 'lodash'
3-
import { Dispatch, FC, ReactNode, SetStateAction, useCallback, useState } from 'react'
3+
import {
4+
Dispatch,
5+
FC,
6+
MutableRefObject,
7+
ReactNode,
8+
SetStateAction,
9+
useCallback,
10+
useEffect,
11+
useRef,
12+
useState,
13+
} from 'react'
414

5-
import { IconSolid } from '../../../../lib'
15+
import { IconSolid, useClickOutside } from '../../../../lib'
616

717
import styles from './CollapsiblePane.module.scss'
818

919
interface CollapsiblePaneProps {
1020
children: ReactNode
21+
isOpen?: boolean
1122
onToggle?: (isOpen: boolean) => void
1223
position?: 'to-left'|'to-right'
1324
title: string
@@ -17,13 +28,26 @@ const CollapsiblePane: FC<CollapsiblePaneProps> = (props: CollapsiblePaneProps)
1728
const {onToggle = noop}: CollapsiblePaneProps = props
1829
const [isOpen, setIsOpen]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
1930

31+
const elRef: MutableRefObject<HTMLElement | any> = useRef()
32+
2033
const toggle: () => void = useCallback(() => {
2134
setIsOpen(!isOpen)
2235
onToggle(!isOpen)
2336
}, [isOpen, onToggle])
2437

38+
const close: () => void = useCallback(() => {
39+
setIsOpen(false)
40+
onToggle(false)
41+
}, [onToggle])
42+
43+
useEffect(() => {
44+
setIsOpen(!!props.isOpen)
45+
}, [props.isOpen])
46+
47+
useClickOutside(elRef.current, close, isOpen)
48+
2549
return (
26-
<div className={
50+
<div ref={elRef} className={
2751
classNames(
2852
styles['wrap'],
2953
props.position ?? 'to-left',

src-ts/tools/learn/learn-lib/course-outline/CourseOutline.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import styles from './CourseOutline.module.scss'
1616
interface CourseOutlineProps {
1717
course?: LearnCourse
1818
currentStep?: string
19+
onItemNavigate: (item: LearnLesson) => void
1920
progress?: LearnUserCertificationProgress
2021
ready?: boolean
2122
}
@@ -52,6 +53,7 @@ const CourseOutline: FC<CourseOutlineProps> = (props: CourseOutlineProps) => {
5253
progress={props.progress?.modules}
5354
shortDescription={module.meta.introCopy}
5455
title={module.meta.name}
56+
onItemClick={props.onItemNavigate}
5557
/>
5658
))}
5759
</div>

src-ts/tools/learn/learn-lib/course-outline/collapsible-item/CollapsibleItem.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface CollapsibleItemProps {
2121
items: Array<CollapsibleListItem>
2222
lessonsCount: number
2323
moduleKey: string
24+
onItemClick: (item: any) => void
2425
path?: (item: any) => string
2526
progress?: LearnUserCertificationProgress['modules']
2627
shortDescription: Array<string>
@@ -72,6 +73,7 @@ const CollapsibleItem: FC<CollapsibleItemProps> = (props: CollapsibleItemProps)
7273
<li
7374
key={key}
7475
className={classNames(styles['item-wrap'], !stepCount && 'full-width')}
76+
onClick={() => props.onItemClick(item)}
7577
>
7678
{props.path ? (
7779
<Link className={styles['item-wrap']} to={props.path(item)}>

0 commit comments

Comments
 (0)