|
1 | 1 | import PropTypes from 'prop-types'; |
2 | | -import React, {Fragment, useRef, useEffect} from 'react'; |
| 2 | +import React, {Fragment} from 'react'; |
3 | 3 | import classNames from 'classnames'; |
4 | 4 | import {FormattedMessage} from 'react-intl'; |
5 | 5 | import Draggable from 'react-draggable'; |
@@ -99,6 +99,20 @@ class VideoStep extends React.Component { |
99 | 99 | script2.async = true; |
100 | 100 | script2.setAttribute('id', 'wistia-video-api'); |
101 | 101 | document.body.appendChild(script2); |
| 102 | + |
| 103 | + // The Wistia API doesn't provide a callback for when the video is ready, |
| 104 | + // so we use the global _wq queue that Wistia provides for this purpose. |
| 105 | + // See the below for more details. |
| 106 | + // https://docs.wistia.com/docs/javascript-player-api#with-standard-embeds |
| 107 | + window._wq = window._wq || []; |
| 108 | + window._wq.push({ |
| 109 | + id: this.props.video, |
| 110 | + onReady: video => { |
| 111 | + if (video) { |
| 112 | + video.focus(); |
| 113 | + } |
| 114 | + }}); |
| 115 | + |
102 | 116 | } |
103 | 117 |
|
104 | 118 | // We use the Wistia API here to update or pause the video dynamically: |
@@ -127,6 +141,10 @@ class VideoStep extends React.Component { |
127 | 141 |
|
128 | 142 | const script2 = document.getElementById('wistia-video-api'); |
129 | 143 | script2.parentNode.removeChild(script2); |
| 144 | + |
| 145 | + // Clean up the _wq queue to prevent old callbacks from firing |
| 146 | + // if the component is unmounted before the video is ready |
| 147 | + window._wq = window._wq.filter(video => video.id !== this.props.video); |
130 | 148 | } |
131 | 149 |
|
132 | 150 | render () { |
@@ -354,21 +372,6 @@ const Cards = props => { |
354 | 372 |
|
355 | 373 | if (activeDeckId === null) return; |
356 | 374 |
|
357 | | - const cardRef = useRef(null); |
358 | | - |
359 | | - useEffect(() => { |
360 | | - // Only focus if there’s an actual tutorial step (image/video) |
361 | | - const steps = content[activeDeckId]?.steps; |
362 | | - const isTutorialStep = steps?.[step]?.video; |
363 | | - |
364 | | - if (isTutorialStep && cardRef.current) { |
365 | | - // Defer focus to next animation frame for layout stability |
366 | | - requestAnimationFrame(() => { |
367 | | - cardRef.current.focus(); |
368 | | - }); |
369 | | - } |
370 | | - }, [activeDeckId, step, content]); |
371 | | - |
372 | 375 | // Tutorial cards need to calculate their own dragging bounds |
373 | 376 | // to allow for dragging the cards off the left, right and bottom |
374 | 377 | // edges of the workspace. |
@@ -400,8 +403,6 @@ const Cards = props => { |
400 | 403 | top: `${menuBarHeight}px`, |
401 | 404 | left: `${-cardHorizontalDragOffset}px` |
402 | 405 | }} |
403 | | - ref={cardRef} |
404 | | - tabIndex={-1} |
405 | 406 | > |
406 | 407 | <Draggable |
407 | 408 | bounds="parent" |
|
0 commit comments