1
- import React , { useEffect , useCallback , useState } from 'react'
1
+ import React , { useCallback , useState } from 'react'
2
2
import { useTranslation } from 'react-i18next'
3
3
import Spinner from 'widgets/Spinner'
4
4
import Dialog from 'widgets/Dialog'
@@ -9,59 +9,23 @@ import { cacheClearDate } from 'services/localCache'
9
9
import { isSuccessResponse , uniformTimeFormatter } from 'utils'
10
10
import styles from './clearCache.module.scss'
11
11
12
- const I18N_PATH = 'settings.clear-cache'
13
- const IDs = {
14
- submitClearCache : 'submit-clear-cache' ,
15
- refreshCacheOption : 'refresh-cache-option' ,
16
- rebuildCacheOption : 'rebuild-cache-option' ,
17
- }
18
-
19
12
const ClearCacheDialog = ( {
20
13
dispatch,
21
14
className,
22
15
btnClassName,
23
- hideRebuild,
24
16
} : {
25
17
dispatch : StateDispatch
26
18
className ?: string
27
19
btnClassName ?: string
28
- hideRebuild ?: boolean
29
20
} ) => {
30
21
const [ t ] = useTranslation ( )
31
22
const [ clearedDate , setClearedDate ] = useState ( cacheClearDate . load ( ) )
32
23
const [ isClearing , setIsClearing ] = useState ( false )
33
- const [ isDialogOpen , setIsDialogOpen ] = useState ( false )
34
- const [ isRebuild , setIsRebuild ] = useState ( false )
35
24
const [ notice , setNotice ] = useState ( '' )
36
25
37
- const showDialog = useCallback ( ( ) => {
38
- setIsDialogOpen ( true )
39
- } , [ setIsDialogOpen ] )
40
-
41
- const dismissDialog = useCallback ( ( ) => {
42
- setIsDialogOpen ( false )
43
- } , [ setIsDialogOpen ] )
44
-
45
- const toggleIsRebuild = useCallback (
46
- ( e : React . ChangeEvent < HTMLInputElement > ) => {
47
- setIsRebuild ( e . target . checked )
48
- } ,
49
- [ setIsRebuild ]
50
- )
51
-
52
- useEffect ( ( ) => {
53
- if ( isDialogOpen ) {
54
- /* eslint-disable-next-line no-unused-expressions */
55
- document . querySelector < HTMLButtonElement > ( `#${ IDs . submitClearCache } ` ) ?. focus ( )
56
- } else {
57
- setIsRebuild ( false )
58
- }
59
- } , [ isDialogOpen , setIsRebuild ] )
60
-
61
26
const handleSubmit = useCallback ( ( ) => {
62
- setIsDialogOpen ( false )
63
27
setIsClearing ( true )
64
- clearCellCache ( { resetIndexerData : isRebuild } )
28
+ clearCellCache ( )
65
29
. then ( res => {
66
30
if ( isSuccessResponse ( res ) && res . result ) {
67
31
addPopup ( 'clear-cache-successfully' ) ( dispatch )
@@ -74,7 +38,7 @@ const ClearCacheDialog = ({
74
38
. finally ( ( ) => {
75
39
setIsClearing ( false )
76
40
} )
77
- } , [ dispatch , setClearedDate , setIsDialogOpen , isRebuild ] )
41
+ } , [ dispatch , setClearedDate ] )
78
42
79
43
return (
80
44
< >
@@ -83,10 +47,10 @@ const ClearCacheDialog = ({
83
47
< button
84
48
type = "button"
85
49
className = { `${ btnClassName } ${ styles . clearBtn } ` }
86
- onClick = { showDialog }
50
+ onClick = { handleSubmit }
87
51
disabled = { isClearing }
88
52
>
89
- { t ( 'settings.data.clear-cache ' ) }
53
+ { t ( 'settings.data.refresh ' ) }
90
54
</ button >
91
55
</ div >
92
56
@@ -96,29 +60,6 @@ const ClearCacheDialog = ({
96
60
< p > { t ( 'settings.data.clearing-cache' ) } </ p >
97
61
</ div >
98
62
</ Dialog >
99
-
100
- < Dialog
101
- show = { isDialogOpen }
102
- title = { t ( `${ I18N_PATH } .title` ) }
103
- onConfirm = { handleSubmit }
104
- onCancel = { dismissDialog }
105
- confirmText = { t ( 'settings.data.confirm-clear' ) }
106
- confirmProps = { { id : IDs . submitClearCache } }
107
- >
108
- < div className = { styles . options } >
109
- < label htmlFor = { IDs . refreshCacheOption } >
110
- < input type = "checkbox" id = { IDs . refreshCacheOption } checked disabled />
111
- < span className = { styles . highlight } > { t ( `${ I18N_PATH } .options.refresh.label` ) } </ span >
112
- </ label >
113
- { hideRebuild ? null : (
114
- < label htmlFor = { IDs . rebuildCacheOption } >
115
- < input type = "checkbox" id = { IDs . rebuildCacheOption } checked = { isRebuild } onChange = { toggleIsRebuild } />
116
- < span > { t ( `${ I18N_PATH } .options.rebuild.label` ) } </ span >
117
- </ label >
118
- ) }
119
- </ div >
120
- </ Dialog >
121
-
122
63
< Toast content = { notice } onDismiss = { ( ) => setNotice ( '' ) } />
123
64
</ >
124
65
)
0 commit comments