1
- import { VStack , Container , Heading } from '@chakra-ui/core' ;
1
+ import { VStack , Container , Heading , Button } from '@chakra-ui/core' ;
2
2
import * as React from 'react' ;
3
- import { useEffect } from 'react' ;
3
+ import { useCallback , useEffect , useState } from 'react' ;
4
4
import { TimeSlider } from './components/TimeSlider' ;
5
5
import { Waveforms } from './components/Waveforms' ;
6
6
import { useWaveforms } from './hooks/useWaveforms' ;
7
7
8
8
export function LoaderDemo ( ) {
9
- const [ runAnimation , setRunAnimation ] = React . useState ( true ) ;
10
- const [ requestOffset , setRequestOffset ] = React . useState ( 100 ) ;
11
- const [ requestDuration , setRequestDuration ] = React . useState ( 500 ) ;
12
- const [ debounceDelay , setDebounceDelay ] = React . useState ( 300 ) ;
13
- const [ debounceTimeOn , setDebounceTimeOn ] = React . useState ( 500 ) ;
9
+ const [ runAnimation , setRunAnimation ] = useState ( false ) ;
10
+ const [ requestOffset , setRequestOffset ] = useState ( 100 ) ;
11
+ const [ requestDuration , setRequestDuration ] = useState ( 500 ) ;
12
+ const [ debounceDelay , setDebounceDelay ] = useState ( 300 ) ;
13
+ const [ debounceTimeOn , setDebounceTimeOn ] = useState ( 500 ) ;
14
+ const [ startClicked , setStartClicked ] = useState ( false ) ;
14
15
15
16
const totalLength = 3000 ;
16
17
17
18
const {
18
19
x,
19
20
done,
20
21
reset,
22
+
23
+ isLoading,
21
24
originalOffset,
22
25
originalLength,
23
26
27
+ debouncedIsLoading,
24
28
debouncedOffset,
25
29
debouncedLength,
26
30
31
+ debouncedIsLoading2,
27
32
debouncedOffset2,
28
33
debouncedLength2,
29
-
30
- isLoading,
31
- debouncedIsLoading,
32
- debouncedIsLoading2,
33
34
} = useWaveforms ( {
34
35
scanMode : runAnimation ,
35
36
requestOffset : requestOffset ,
@@ -39,11 +40,25 @@ export function LoaderDemo() {
39
40
totalLength : totalLength ,
40
41
} ) ;
41
42
42
- useEffect ( ( ) => {
43
+ const start = useCallback ( ( ) => {
44
+ setStartClicked ( true ) ;
43
45
reset ( ) ;
44
-
45
46
setRunAnimation ( true ) ;
46
- } , [ requestOffset , requestDuration , debounceDelay , debounceTimeOn , reset ] ) ;
47
+ } , [ reset ] ) ;
48
+
49
+ useEffect ( ( ) => {
50
+ if ( startClicked ) {
51
+ start ( ) ;
52
+ }
53
+ } , [
54
+ requestOffset ,
55
+ requestDuration ,
56
+ debounceDelay ,
57
+ debounceTimeOn ,
58
+ reset ,
59
+ start ,
60
+ startClicked ,
61
+ ] ) ;
47
62
48
63
useEffect ( ( ) => {
49
64
if ( done ) {
@@ -84,6 +99,10 @@ export function LoaderDemo() {
84
99
onValueChange = { setDebounceTimeOn }
85
100
/>
86
101
102
+ < Button size = "lg" onClick = { start } disabled = { runAnimation } >
103
+ Start
104
+ </ Button >
105
+
87
106
< Waveforms
88
107
totalLength = { totalLength }
89
108
x = { x }
0 commit comments