@@ -56,6 +56,7 @@ const MatchPage = ({ params }) => {
5656 const [ bookmarks , setBookmarks ] = useState ( [ ] )
5757 const [ triggerScroll , setTriggerScroll ] = useState ( false )
5858 const [ autoplayEnabled , setAutoplayEnabled ] = useState ( true )
59+ const autoplaySuppressedRef = useRef ( false )
5960 const tableRef = useRef ( null )
6061 const iframeRef = useRef ( null )
6162 const filterSubmitRef = useRef ( null )
@@ -132,11 +133,14 @@ const MatchPage = ({ params }) => {
132133 }
133134 } , [ matchData ] )
134135
135- const handleJumpToTime = ( time ) => {
136- if ( videoObject && videoObject . seekTo ) {
137- videoObject . seekTo ( time / 1000 , true )
138- }
139- }
136+ const handleJumpToTime = useCallback (
137+ ( time ) => {
138+ if ( videoObject && videoObject . seekTo ) {
139+ videoObject . seekTo ( time / 1000 , true )
140+ }
141+ } ,
142+ [ videoObject ]
143+ )
140144
141145 const returnFilteredPoints = useCallback ( ( ) => {
142146 let filteredPoints = matchData . pointsJson
@@ -165,6 +169,7 @@ const MatchPage = ({ params }) => {
165169 useEffect ( ( ) => {
166170 if ( ! videoObject || ! autoplayEnabled ) return
167171 const interval = setInterval ( ( ) => {
172+ if ( autoplaySuppressedRef . current ) return
168173 if ( videoObject && typeof videoObject . getCurrentTime === 'function' ) {
169174 const currentTime = videoObject . getCurrentTime ( ) * 1000 // Convert to ms
170175 const filteredPoints = returnFilteredPoints ( ) . sort (
@@ -247,27 +252,61 @@ const MatchPage = ({ params }) => {
247252 }
248253 } , [ triggerScroll , showHTML , showPDF ] )
249254
255+ const suppressAutoplay = useCallback ( ( ) => {
256+ autoplaySuppressedRef . current = true
257+ setTimeout ( ( ) => {
258+ autoplaySuppressedRef . current = false
259+ } , 3000 )
260+ } , [ ] )
261+
250262 const handlePrevPoint = useCallback ( ( ) => {
251263 if ( ! videoObject ) return
252264 const currentTime = videoObject . getCurrentTime ( ) * 1000
253265 const points = returnFilteredPoints ( ) . sort (
254266 ( a , b ) => a . Position - b . Position
255267 )
256- const prevPoint = [ ...points ]
257- . reverse ( )
258- . find ( ( p ) => p . Position < currentTime - 1000 )
259- if ( prevPoint ) handleJumpToTime ( prevPoint . Position )
260- } , [ videoObject , returnFilteredPoints ] )
268+ // Find the index of the current/most-recent point
269+ let currentIndex = - 1
270+ for ( let i = points . length - 1 ; i >= 0 ; i -- ) {
271+ if ( points [ i ] . Position <= currentTime + 500 ) {
272+ currentIndex = i
273+ break
274+ }
275+ }
276+ // If we're very close to the start of the current point, go to the one before it
277+ if (
278+ currentIndex >= 0 &&
279+ currentTime - points [ currentIndex ] . Position < 2000 &&
280+ currentIndex > 0
281+ ) {
282+ currentIndex -= 1
283+ }
284+ if ( currentIndex >= 0 ) {
285+ suppressAutoplay ( )
286+ handleJumpToTime ( points [ currentIndex ] . Position )
287+ }
288+ } , [ videoObject , returnFilteredPoints , suppressAutoplay , handleJumpToTime ] )
261289
262290 const handleNextPoint = useCallback ( ( ) => {
263291 if ( ! videoObject ) return
264292 const currentTime = videoObject . getCurrentTime ( ) * 1000
265293 const points = returnFilteredPoints ( ) . sort (
266294 ( a , b ) => a . Position - b . Position
267295 )
268- const nextPoint = points . find ( ( p ) => p . Position > currentTime + 500 )
269- if ( nextPoint ) handleJumpToTime ( nextPoint . Position )
270- } , [ videoObject , returnFilteredPoints ] )
296+ // Find the index of the current/most-recent point
297+ let currentIndex = - 1
298+ for ( let i = points . length - 1 ; i >= 0 ; i -- ) {
299+ if ( points [ i ] . Position <= currentTime + 500 ) {
300+ currentIndex = i
301+ break
302+ }
303+ }
304+ const nextIndex = currentIndex + 1
305+ if ( nextIndex < points . length ) {
306+ suppressAutoplay ( )
307+ handleJumpToTime ( points [ nextIndex ] . Position )
308+ }
309+ } , [ videoObject , returnFilteredPoints , suppressAutoplay , handleJumpToTime ] )
271310
272311 const removeFilter = ( key , value ) => {
273312 const updatedFilterList = filterList . filter (
@@ -308,9 +347,7 @@ const MatchPage = ({ params }) => {
308347
309348 return (
310349 < div className = { styles . container } >
311- { /* Compact single-row header */ }
312350 < MatchTiles
313- compact
314351 clientTeam = { matchData . teams . clientTeam }
315352 opponentTeam = { matchData . teams . opponentTeam }
316353 matchDetails = {
0 commit comments