@@ -11,24 +11,43 @@ const usePaths = (chapters, track, trackPosition) => {
1111 . flatMap ( ( chapter ) => chapter . videos )
1212 . flatMap ( ( video ) =>
1313 video . parts ?. length > 0
14- ? video . parts . map ( ( _ , partIndex ) => ( { slug : video . slug , partIndex } ) )
15- : [ { slug : video . slug , partIndex : 0 } ]
14+ ? video . parts . map ( ( _ , partIndex ) => ( {
15+ slug : video . slug ,
16+ partIndex,
17+ isMultiPart : true
18+ } ) )
19+ : [ { slug : video . slug , partIndex : 0 , isMultiPart : false } ]
1620 ) ;
17- const partIndex = useChallengePartIndex ( ) ;
1821 const currentVideo =
1922 chapters [ trackPosition . chapterIndex ] . videos [ trackPosition . videoIndex ] ;
23+ const totalParts = flatTrack . filter (
24+ ( video ) => video . slug === currentVideo . slug
25+ ) . length ;
26+ const partIndex = useChallengePartIndex ( totalParts ) ;
2027 const currentIndex = flatTrack . findIndex (
2128 ( video ) => video . slug === currentVideo . slug && video . partIndex === partIndex
2229 ) ;
2330 const prevVideo = flatTrack [ currentIndex - 1 ] ;
2431 const nextVideo = flatTrack [ currentIndex + 1 ] ;
25- const computePath = ( video ) =>
26- video ? { ...video , path : `/tracks/${ track . slug } /${ video . slug } ` } : null ;
27- return [ computePath ( prevVideo ) , computePath ( nextVideo ) ] ;
32+ const computePath = ( video ) => {
33+ if ( video ) {
34+ const hash = video . isMultiPart ? `#part-${ video . partIndex + 1 } ` : '' ;
35+ return {
36+ ...video ,
37+ path : `/tracks/${ track . slug } /${ video . slug } ${ hash } `
38+ } ;
39+ }
40+ return null ;
41+ } ;
42+ return [ computePath ( prevVideo ) , computePath ( nextVideo ) , partIndex ] ;
2843} ;
2944
3045const OverviewTimeline = ( { className, chapters, track, trackPosition } ) => {
31- const [ previousVideo , nextVideo ] = usePaths ( chapters , track , trackPosition ) ;
46+ const [ previousVideo , nextVideo , currentPartIndex ] = usePaths (
47+ chapters ,
48+ track ,
49+ trackPosition
50+ ) ;
3251
3352 const timelineRef = usePersistScrollPosition ( track . slug , 'tracks' ) ;
3453 return (
@@ -42,23 +61,18 @@ const OverviewTimeline = ({ className, chapters, track, trackPosition }) => {
4261 chapters = { chapters }
4362 track = { track }
4463 trackPosition = { trackPosition }
64+ currentPartIndex = { currentPartIndex }
4565 />
4666 ) ) }
4767 </ div >
4868 < div className = { css . navigation } >
4969 { previousVideo !== null && (
50- < Link
51- className = { css . navButton }
52- to = { previousVideo . path }
53- state = { { challengePartIndex : previousVideo . partIndex } } >
70+ < Link className = { css . navButton } to = { previousVideo . path } >
5471 Previous
5572 </ Link >
5673 ) }
5774 { nextVideo !== null && (
58- < Link
59- className = { css . navButton }
60- to = { nextVideo . path }
61- state = { { challengePartIndex : nextVideo . partIndex } } >
75+ < Link className = { css . navButton } to = { nextVideo . path } >
6276 Next
6377 </ Link >
6478 ) }
@@ -68,14 +82,20 @@ const OverviewTimeline = ({ className, chapters, track, trackPosition }) => {
6882} ;
6983
7084const ChapterSection = memo (
71- ( { chapter, chapterIndex, chapters, track, trackPosition } ) => {
85+ ( {
86+ chapter,
87+ chapterIndex,
88+ chapters,
89+ track,
90+ trackPosition,
91+ currentPartIndex
92+ } ) => {
7293 const hasSeenChapter = chapterIndex < trackPosition . chapterIndex ;
7394 const isThisChapter = chapterIndex === trackPosition . chapterIndex ;
7495 const trackPath = `/tracks/${ track . slug } ` ;
7596 const [ collapsed , setCollapsed ] = useState ( false ) ;
7697
7798 const { videoIndex : currentVideoIndex } = trackPosition ;
78- const currentPartIndex = useChallengePartIndex ( ) ;
7999
80100 return (
81101 < ul className = { css . chapterList } >
@@ -117,8 +137,7 @@ const ChapterSection = memo(
117137 [ css . last ] : isLastVideo && partIndex === currentPartIndex
118138 } ) } >
119139 < Link
120- to = { `${ trackPath } /${ video . slug } ` }
121- state = { { challengePartIndex : partIndex } } >
140+ to = { `${ trackPath } /${ video . slug } #part-${ partIndex + 1 } ` } >
122141 { video . title } - { part . title }
123142 </ Link >
124143 </ li >
0 commit comments