Skip to content

Commit 049541b

Browse files
committed
Adding to object in Tracks VideoSection
1 parent 688a20c commit 049541b

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

src/components/tracks/OverviewTimeline.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { memo, useState } from 'react';
22
import cn from 'classnames';
33
import { Link } from 'gatsby';
44

5-
import { useChallengePartIndex, usePersistScrollPosition } from '../../hooks';
5+
import { usePersistScrollPosition } from '../../hooks';
66

77
import * as css from './OverviewTimeline.module.css';
88

@@ -20,12 +20,10 @@ const usePaths = (chapters, track, trackPosition) => {
2020
);
2121
const currentVideo =
2222
chapters[trackPosition.chapterIndex].videos[trackPosition.videoIndex];
23-
const totalParts = flatTrack.filter(
24-
(video) => video.slug === currentVideo.slug
25-
).length;
26-
const partIndex = useChallengePartIndex(totalParts);
2723
const currentIndex = flatTrack.findIndex(
28-
(video) => video.slug === currentVideo.slug && video.partIndex === partIndex
24+
(video) =>
25+
video.slug === currentVideo.slug &&
26+
video.partIndex === trackPosition.partIndex
2927
);
3028
const prevVideo = flatTrack[currentIndex - 1];
3129
const nextVideo = flatTrack[currentIndex + 1];
@@ -39,15 +37,11 @@ const usePaths = (chapters, track, trackPosition) => {
3937
}
4038
return null;
4139
};
42-
return [computePath(prevVideo), computePath(nextVideo), partIndex];
40+
return [computePath(prevVideo), computePath(nextVideo)];
4341
};
4442

4543
const OverviewTimeline = ({ className, chapters, track, trackPosition }) => {
46-
const [previousVideo, nextVideo, currentPartIndex] = usePaths(
47-
chapters,
48-
track,
49-
trackPosition
50-
);
44+
const [previousVideo, nextVideo] = usePaths(chapters, track, trackPosition);
5145

5246
const timelineRef = usePersistScrollPosition(track.slug, 'tracks');
5347
return (
@@ -61,7 +55,6 @@ const OverviewTimeline = ({ className, chapters, track, trackPosition }) => {
6155
chapters={chapters}
6256
track={track}
6357
trackPosition={trackPosition}
64-
currentPartIndex={currentPartIndex}
6558
/>
6659
))}
6760
</div>
@@ -82,14 +75,7 @@ const OverviewTimeline = ({ className, chapters, track, trackPosition }) => {
8275
};
8376

8477
const ChapterSection = memo(
85-
({
86-
chapter,
87-
chapterIndex,
88-
chapters,
89-
track,
90-
trackPosition,
91-
currentPartIndex
92-
}) => {
78+
({ chapter, chapterIndex, chapters, track, trackPosition }) => {
9379
const hasSeenChapter = chapterIndex < trackPosition.chapterIndex;
9480
const isThisChapter = chapterIndex === trackPosition.chapterIndex;
9581
const trackPath = `/tracks/${track.slug}`;
@@ -125,6 +111,7 @@ const ChapterSection = memo(
125111

126112
return isMultiPart ? (
127113
video.parts.map((part, partIndex) => {
114+
const currentPartIndex = trackPosition.partIndex;
128115
const hasSeenPart =
129116
hasSeenVideo &&
130117
(videoIndex < currentVideoIndex ||

src/components/tracks/VideoSection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const VideoSection = ({ track, video, trackPosition, mainTitle }) => {
3737

3838
const totalParts = video.parts?.length || 1;
3939
const partIndex = useChallengePartIndex(totalParts);
40+
trackPosition = { ...trackPosition, partIndex };
4041
const part = video.parts?.[partIndex];
4142
const videoId = part?.videoId ?? video.videoId;
4243
const nebulaSlug = part?.nebulaSlug ?? video.nebulaSlug;

0 commit comments

Comments
 (0)