Skip to content

Commit 29eff63

Browse files
committed
Fix double spins (again)
1 parent a47623f commit 29eff63

File tree

1 file changed

+8
-7
lines changed
  • src/components/index-page/what-is-graphql

1 file changed

+8
-7
lines changed

src/components/index-page/what-is-graphql/wires.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -481,18 +481,16 @@ export function Wires({ className }: { className?: string }) {
481481
const [step, inc] = useReducer(x => (x + 1) % STEPS, 0)
482482

483483
const ref = useRef<SVGSVGElement>(null)
484-
485-
// set to true by manual interaction: we skip the next animation end
486-
// if the animation finishes right after the user's click
487-
const shouldAvoidDoubleSpin = useRef(false)
484+
const backgroundRef = useRef<HTMLButtonElement>(null)
488485

489486
useEffect(() => {
490487
const animate = document.querySelector(
491488
"#paint_sr_pri_highlight_linear_671_9150 animate",
492489
)
493490

494491
const onAnimationRepeat = () => {
495-
if (shouldAvoidDoubleSpin.current) return
492+
// we avoid spinning a second time if the user has just clicked the button
493+
if (backgroundRef.current?.disabled) return
496494
inc()
497495
}
498496

@@ -506,10 +504,12 @@ export function Wires({ className }: { className?: string }) {
506504
const onBackgroundClick = useMemo(
507505
() =>
508506
throttle(() => {
507+
const button = backgroundRef.current
508+
if (!button) return
509+
button.disabled = true
509510
inc()
510-
shouldAvoidDoubleSpin.current = true
511511
setTimeout(() => {
512-
shouldAvoidDoubleSpin.current = false
512+
button.disabled = false
513513
}, 750)
514514
}, 500),
515515
[],
@@ -541,6 +541,7 @@ export function Wires({ className }: { className?: string }) {
541541
<SVGDefinitions />
542542
</svg>
543543
<button
544+
ref={backgroundRef}
544545
tabIndex={-1}
545546
onClick={onBackgroundClick}
546547
aria-label={step === 2 ? "Show query again" : "Next step"}

0 commit comments

Comments
 (0)