22// Knows how to display various modes like tracking, volume, balance, etc.
33import * as React from "react" ;
44import CharacterString from "../CharacterString" ;
5- import * as Actions from "../../actionCreators" ;
65import * as Selectors from "../../selectors" ;
7- import { useTypedSelector , useActionCreator } from "../../hooks" ;
6+ import { useTypedSelector } from "../../hooks" ;
87
98const SEPARATOR = " *** " ;
109
@@ -43,20 +42,24 @@ export const loopText = (text: string): string =>
4342 : text . padEnd ( MARQUEE_MAX_LENGTH , " " ) ;
4443
4544interface UseStepperArgs {
46- step : ( ) => void ;
4745 dragging : boolean ;
46+ disableMarquee : boolean ;
4847}
4948
5049// Call `step` every second, except when dragging. Resume stepping 1 second after dragging ceases.
51- function useStepper ( { step, dragging } : UseStepperArgs ) : void {
50+ function useStepper ( { dragging, disableMarquee } : UseStepperArgs ) : number {
51+ const [ currentStep , setStep ] = React . useState ( 0 ) ;
5252 const [ stepping , setStepping ] = React . useState ( true ) ;
5353 React . useEffect ( ( ) => {
54- if ( stepping === false ) {
54+ if ( stepping === false || disableMarquee === true ) {
5555 return ;
5656 }
57- const stepHandle = setInterval ( step , 220 ) ;
57+ const stepHandle = setInterval (
58+ ( ) => setStep ( ( current ) => current + 1 ) ,
59+ 220
60+ ) ;
5861 return ( ) => clearInterval ( stepHandle ) ;
59- } , [ step , stepping ] ) ;
62+ } , [ stepping , disableMarquee ] ) ;
6063
6164 React . useEffect ( ( ) => {
6265 if ( dragging ) {
@@ -70,6 +73,7 @@ function useStepper({ step, dragging }: UseStepperArgs): void {
7073 window . clearTimeout ( steppingTimeout ) ;
7174 } ;
7275 } , [ dragging ] ) ;
76+ return currentStep ;
7377}
7478
7579// When user calls `handleMouseDown`, and moves the mouse, `dragOffset` will update as they drag.
@@ -118,14 +122,12 @@ function useDragX() {
118122const Marquee = React . memo ( ( ) => {
119123 const text = useTypedSelector ( Selectors . getMarqueeText ) ;
120124 const doubled = useTypedSelector ( Selectors . getDoubled ) ;
121- const marqueeStep = useTypedSelector ( Selectors . getMarqueeStep ) ;
122- const stepMarquee = useActionCreator ( Actions . stepMarquee ) ;
123125 const { handleMouseDown, dragOffset, dragging } = useDragX ( ) ;
126+ const disableMarquee = useTypedSelector ( Selectors . getDisableMarquee ) ;
127+ const marqueeStep = useStepper ( { dragging, disableMarquee } ) ;
124128 const offset = stepOffset ( text , marqueeStep , dragOffset ) ;
125129 const offsetPixels = pixelUnits ( - offset ) ;
126130
127- useStepper ( { step : stepMarquee , dragging } ) ;
128-
129131 return (
130132 < div
131133 id = "marquee"
0 commit comments