File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -3,10 +3,11 @@ import { useDispatch, useSelector } from 'react-redux'
3
3
4
4
import { Bar } from '@/utils/Bar'
5
5
import { RootState } from '@/store'
6
- import {
6
+ import sorting , {
7
7
goToNextStep ,
8
8
goToPreviousStep ,
9
- resetSorting
9
+ resetSorting ,
10
+ getSortingStatus
10
11
} from '@/store/slice/sorting'
11
12
12
13
type IState = number [ ]
@@ -24,6 +25,7 @@ const useSort = (): {
24
25
const { animationSpeed, currentStep, steps, arraySize } = useSelector (
25
26
( state : RootState ) => state . sorting
26
27
)
28
+ const status = useSelector ( getSortingStatus )
27
29
const dispatch = useDispatch ( )
28
30
29
31
const pause = ( ) : void => {
@@ -33,14 +35,18 @@ const useSort = (): {
33
35
34
36
useEffect ( ( ) => {
35
37
pause ( )
36
- return pause
38
+ return ( ) => {
39
+ pause
40
+ }
37
41
} , [ steps , arraySize ] )
38
42
39
43
useEffect ( ( ) => {
40
- if ( currentStep > 0 ) {
44
+ if ( status === 'SORTING' ) {
41
45
sort ( )
42
46
}
43
- return sort
47
+ return ( ) => {
48
+ sort
49
+ }
44
50
} , [ animationSpeed ] )
45
51
46
52
const sort = ( ) : void => {
Original file line number Diff line number Diff line change @@ -141,7 +141,9 @@ export const getCurrentArray = ({ sorting }: RootState): string =>
141
141
sorting . steps [ sorting . currentStep ] . map ( i => i . value ) . join ( ', ' )
142
142
export const getInitialArray = ( { sorting } : RootState ) : string =>
143
143
sorting . initialArray . map ( i => i . value ) . join ( ', ' )
144
- export const getSortingStatus = ( { sorting } : RootState ) : string => {
144
+
145
+ type SortingStatus = BarStatus | 'SORTING'
146
+ export const getSortingStatus = ( { sorting } : RootState ) : SortingStatus => {
145
147
if ( sorting . currentStep === 0 ) {
146
148
return BarStatus . UNSORTED
147
149
} else if (
You can’t perform that action at this time.
0 commit comments