2
2
// Knows how to display various modes like tracking, volume, balance, etc.
3
3
import * as React from "react" ;
4
4
import CharacterString from "../CharacterString" ;
5
- import * as Actions from "../../actionCreators" ;
6
5
import * as Selectors from "../../selectors" ;
7
- import { useTypedSelector , useActionCreator } from "../../hooks" ;
6
+ import { useTypedSelector } from "../../hooks" ;
8
7
9
8
const SEPARATOR = " *** " ;
10
9
@@ -43,20 +42,24 @@ export const loopText = (text: string): string =>
43
42
: text . padEnd ( MARQUEE_MAX_LENGTH , " " ) ;
44
43
45
44
interface UseStepperArgs {
46
- step : ( ) => void ;
47
45
dragging : boolean ;
46
+ disableMarquee : boolean ;
48
47
}
49
48
50
49
// 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 ) ;
52
52
const [ stepping , setStepping ] = React . useState ( true ) ;
53
53
React . useEffect ( ( ) => {
54
- if ( stepping === false ) {
54
+ if ( stepping === false || disableMarquee === true ) {
55
55
return ;
56
56
}
57
- const stepHandle = setInterval ( step , 220 ) ;
57
+ const stepHandle = setInterval (
58
+ ( ) => setStep ( ( current ) => current + 1 ) ,
59
+ 220
60
+ ) ;
58
61
return ( ) => clearInterval ( stepHandle ) ;
59
- } , [ step , stepping ] ) ;
62
+ } , [ stepping , disableMarquee ] ) ;
60
63
61
64
React . useEffect ( ( ) => {
62
65
if ( dragging ) {
@@ -70,6 +73,7 @@ function useStepper({ step, dragging }: UseStepperArgs): void {
70
73
window . clearTimeout ( steppingTimeout ) ;
71
74
} ;
72
75
} , [ dragging ] ) ;
76
+ return currentStep ;
73
77
}
74
78
75
79
// When user calls `handleMouseDown`, and moves the mouse, `dragOffset` will update as they drag.
@@ -118,14 +122,12 @@ function useDragX() {
118
122
const Marquee = React . memo ( ( ) => {
119
123
const text = useTypedSelector ( Selectors . getMarqueeText ) ;
120
124
const doubled = useTypedSelector ( Selectors . getDoubled ) ;
121
- const marqueeStep = useTypedSelector ( Selectors . getMarqueeStep ) ;
122
- const stepMarquee = useActionCreator ( Actions . stepMarquee ) ;
123
125
const { handleMouseDown, dragOffset, dragging } = useDragX ( ) ;
126
+ const disableMarquee = useTypedSelector ( Selectors . getDisableMarquee ) ;
127
+ const marqueeStep = useStepper ( { dragging, disableMarquee } ) ;
124
128
const offset = stepOffset ( text , marqueeStep , dragOffset ) ;
125
129
const offsetPixels = pixelUnits ( - offset ) ;
126
130
127
- useStepper ( { step : stepMarquee , dragging } ) ;
128
-
129
131
return (
130
132
< div
131
133
id = "marquee"
0 commit comments