1- import React , { useCallback , useMemo } from 'react'
1+ import React , { useCallback , useMemo , useState } from 'react'
22import { useTranslation } from 'react-i18next'
33import ClearCache from 'components/ClearCache'
44import { useDispatch , useState as useGlobalState } from 'states'
55import { shell } from 'electron'
66import Tooltip from 'widgets/Tooltip'
77import { NetworkType } from 'utils/const'
8- import { Attention } from 'widgets/Icons/icon'
9- import MigrateCkbDataDialog from 'widgets/MigrateCkbDataDialog'
8+ import { Attention , More } from 'widgets/Icons/icon'
9+ import Toast from 'widgets/Toast'
10+ import ModifyPathDialog from 'components/ModifyPathDialog'
11+ import AlertDialog from 'widgets/AlertDialog'
12+ import { isSuccessResponse } from 'utils'
1013import { useDataPath } from './hooks'
1114
1215import styles from './dataSetting.module.scss'
@@ -28,9 +31,33 @@ const PathItem = ({
2831 < button className = { styles . itemPath } type = "button" onClick = { openPath } >
2932 { path }
3033 </ button >
31- < button className = { styles . itemBtn } type = "button" onClick = { handleClick } disabled = { disabled } >
32- { t ( 'settings.data.set-path' ) }
33- </ button >
34+ < Tooltip
35+ className = { styles . moreTooltip }
36+ tipClassName = { styles . moreTip }
37+ tip = {
38+ < div className = { styles . actions } >
39+ { [
40+ {
41+ label : 'settings.data.browse-local-files' ,
42+ onClick : openPath ,
43+ } ,
44+ {
45+ label : 'settings.data.modify-path' ,
46+ onClick : handleClick ,
47+ } ,
48+ ] . map ( ( { label, onClick } ) => (
49+ < button type = "button" key = { label } onClick = { onClick } >
50+ < span > { t ( label ) } </ span >
51+ </ button >
52+ ) ) }
53+ </ div >
54+ }
55+ trigger = "click"
56+ >
57+ < button className = { styles . itemBtn } type = "button" disabled = { disabled } >
58+ < More />
59+ </ button >
60+ </ Tooltip >
3461 </ div >
3562 )
3663}
@@ -42,16 +69,31 @@ const DataSetting = () => {
4269 chain : { networkID } ,
4370 settings : { networks = [ ] } ,
4471 } = useGlobalState ( )
72+ const [ notice , setNotice ] = useState ( '' )
73+ const [ showLostDialog , setShowLostDialog ] = useState ( false )
4574 const network = useMemo ( ( ) => networks . find ( n => n . id === networkID ) , [ networkID , networks ] )
46- const { onSetting, prevPath, currentPath, isDialogOpen, onCancel, onConfirm } = useDataPath ( network )
75+ const { isDialogOpen, openDialog, onSetting, prevPath, currentPath, onCancel, onConfirm, onResync } =
76+ useDataPath ( network )
4777
4878 const openPath = useCallback ( ( ) => {
49- if ( prevPath ) {
50- shell . openPath ( prevPath ! )
51- }
52- } , [ prevPath ] )
79+ shell . openPath ( prevPath ) . then ( res => {
80+ if ( res ) {
81+ setShowLostDialog ( true )
82+ }
83+ } )
84+ } , [ prevPath , onResync ] )
5385 const isLightClient = network ?. type === NetworkType . Light
5486 const hiddenDataPath = isLightClient || ! network ?. readonly
87+
88+ const handleResync = useCallback ( ( ) => {
89+ setShowLostDialog ( false )
90+ onResync ( ) . then ( res => {
91+ if ( isSuccessResponse ( res ) ) {
92+ openPath ( )
93+ }
94+ } )
95+ } , [ openPath ] )
96+
5597 return (
5698 < >
5799 < div className = { styles . root } >
@@ -82,17 +124,36 @@ const DataSetting = () => {
82124 </ div >
83125 </ div >
84126 < div className = { styles . rightContainer } >
85- { hiddenDataPath ? null : < PathItem path = { prevPath } openPath = { openPath } handleClick = { onSetting } /> }
127+ { hiddenDataPath ? null : < PathItem path = { prevPath } openPath = { openPath } handleClick = { openDialog } /> }
86128 < ClearCache className = { styles . item } btnClassName = { styles . itemBtn } dispatch = { dispatch } />
87129 </ div >
88130 </ div >
89- < MigrateCkbDataDialog
90- show = { isDialogOpen }
91- prevPath = { prevPath }
92- currentPath = { currentPath }
93- onCancel = { onCancel }
94- onConfirm = { onConfirm }
95- />
131+
132+ { isDialogOpen && (
133+ < ModifyPathDialog
134+ prevPath = { prevPath }
135+ currentPath = { currentPath }
136+ onCancel = { onCancel }
137+ onConfirm = { onConfirm }
138+ onSetting = { onSetting }
139+ setNotice = { setNotice }
140+ />
141+ ) }
142+
143+ { showLostDialog && (
144+ < AlertDialog
145+ show
146+ title = { t ( 'settings.data.sync-file-lost' ) }
147+ message = { t ( 'settings.data.sync-file-lost-notice' ) }
148+ type = "warning"
149+ cancelText = { t ( 'settings.data.resync' ) }
150+ onCancel = { handleResync }
151+ okText = { t ( 'settings.data.retry' ) }
152+ onOk = { ( ) => setShowLostDialog ( false ) }
153+ />
154+ ) }
155+
156+ < Toast content = { notice } onDismiss = { ( ) => setNotice ( '' ) } />
96157 </ >
97158 )
98159}
0 commit comments