Skip to content

Commit d4fc1d1

Browse files
committed
Closing timeline panel on video selection (on mobile)
1 parent 049541b commit d4fc1d1

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

src/components/challenges/PartsTimeline.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import cn from 'classnames';
44
import * as css from './PartsTimeline.module.css';
55
import { Link } from 'gatsby';
66

7-
const PartsTimeline = ({ className, parts, currentPartIndex }) => {
7+
const PartsTimeline = ({
8+
className,
9+
parts,
10+
currentPartIndex,
11+
onSelection = () => {}
12+
}) => {
813
return (
914
<div className={cn(css.root, className)}>
1015
<div className={css.partsTimeline}>
@@ -16,19 +21,27 @@ const PartsTimeline = ({ className, parts, currentPartIndex }) => {
1621
[css.seen]: index <= currentPartIndex,
1722
[css.last]: index === currentPartIndex
1823
})}>
19-
<Link to={`#part-${index + 1}`}>{part.title}</Link>
24+
<Link to={`#part-${index + 1}`} onClick={onSelection}>
25+
{part.title}
26+
</Link>
2027
</li>
2128
))}
2229
</ul>
2330
</div>
2431
<div className={css.navigation}>
2532
{currentPartIndex > 0 && (
26-
<Link to={`#part-${currentPartIndex}`} className={css.navButton}>
33+
<Link
34+
to={`#part-${currentPartIndex}`}
35+
className={css.navButton}
36+
onClick={onSelection}>
2737
Previous
2838
</Link>
2939
)}
3040
{currentPartIndex < parts.length - 1 && (
31-
<Link to={`#part-${currentPartIndex + 2}`} className={css.navButton}>
41+
<Link
42+
to={`#part-${currentPartIndex + 2}`}
43+
className={css.navButton}
44+
onClick={onSelection}>
3245
Next
3346
</Link>
3447
)}

src/components/challenges/VideoSection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ const VideoSection = ({ challenge }) => {
148148
})}
149149
parts={challenge.parts}
150150
currentPartIndex={activePartIndex}
151+
onSelection={() => setShowTimeline(false)}
151152
/>
152153
)}
153154
{hasTimestamps && (

src/components/tracks/OverviewTimeline.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ const usePaths = (chapters, track, trackPosition) => {
4040
return [computePath(prevVideo), computePath(nextVideo)];
4141
};
4242

43-
const OverviewTimeline = ({ className, chapters, track, trackPosition }) => {
43+
const OverviewTimeline = ({
44+
className,
45+
chapters,
46+
track,
47+
trackPosition,
48+
onSelection = () => {}
49+
}) => {
4450
const [previousVideo, nextVideo] = usePaths(chapters, track, trackPosition);
4551

4652
const timelineRef = usePersistScrollPosition(track.slug, 'tracks');
@@ -55,17 +61,24 @@ const OverviewTimeline = ({ className, chapters, track, trackPosition }) => {
5561
chapters={chapters}
5662
track={track}
5763
trackPosition={trackPosition}
64+
onSelection={onSelection}
5865
/>
5966
))}
6067
</div>
6168
<div className={css.navigation}>
6269
{previousVideo !== null && (
63-
<Link className={css.navButton} to={previousVideo.path}>
70+
<Link
71+
className={css.navButton}
72+
to={previousVideo.path}
73+
onClick={onSelection}>
6474
Previous
6575
</Link>
6676
)}
6777
{nextVideo !== null && (
68-
<Link className={css.navButton} to={nextVideo.path}>
78+
<Link
79+
className={css.navButton}
80+
to={nextVideo.path}
81+
onClick={onSelection}>
6982
Next
7083
</Link>
7184
)}
@@ -75,7 +88,7 @@ const OverviewTimeline = ({ className, chapters, track, trackPosition }) => {
7588
};
7689

7790
const ChapterSection = memo(
78-
({ chapter, chapterIndex, chapters, track, trackPosition }) => {
91+
({ chapter, chapterIndex, chapters, track, trackPosition, onSelection }) => {
7992
const hasSeenChapter = chapterIndex < trackPosition.chapterIndex;
8093
const isThisChapter = chapterIndex === trackPosition.chapterIndex;
8194
const trackPath = `/tracks/${track.slug}`;
@@ -124,7 +137,8 @@ const ChapterSection = memo(
124137
[css.last]: isLastVideo && partIndex === currentPartIndex
125138
})}>
126139
<Link
127-
to={`${trackPath}/${video.slug}#part-${partIndex + 1}`}>
140+
to={`${trackPath}/${video.slug}#part-${partIndex + 1}`}
141+
onClick={onSelection}>
128142
{video.title} - {part.title}
129143
</Link>
130144
</li>
@@ -137,7 +151,9 @@ const ChapterSection = memo(
137151
[css.seen]: hasSeenVideo,
138152
[css.last]: isLastVideo
139153
})}>
140-
<Link to={`${trackPath}/${video.slug}`}>{video.title}</Link>
154+
<Link to={`${trackPath}/${video.slug}`} onClick={onSelection}>
155+
{video.title}
156+
</Link>
141157
</li>
142158
);
143159
})}

src/components/tracks/VideoSection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ const VideoSection = ({ track, video, trackPosition, mainTitle }) => {
3535

3636
const { title, topics, languages } = video;
3737

38-
const totalParts = video.parts?.length || 1;
39-
const partIndex = useChallengePartIndex(totalParts);
38+
const partIndex = useChallengePartIndex(video.parts?.length || 1);
4039
trackPosition = { ...trackPosition, partIndex };
4140
const part = video.parts?.[partIndex];
4241
const videoId = part?.videoId ?? video.videoId;
@@ -181,6 +180,7 @@ const VideoSection = ({ track, video, trackPosition, mainTitle }) => {
181180
chapters={chapters}
182181
track={track}
183182
trackPosition={trackPosition}
183+
onSelection={() => setShowTimeline(false)}
184184
/>
185185
)}
186186
</div>

0 commit comments

Comments
 (0)