Skip to content

Commit

Permalink
feat: Show popup message when clearing cache finishes
Browse files Browse the repository at this point in the history
  • Loading branch information
ashchan committed Nov 17, 2019
1 parent 7419d37 commit 7dfe670
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
24 changes: 7 additions & 17 deletions packages/neuron-ui/src/components/GeneralSetting/index.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
import React, { useCallback, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Stack, PrimaryButton, Spinner } from 'office-ui-fabric-react'
import { StateWithDispatch, AppActions } from 'states/stateProvider/reducer'
import { StateWithDispatch } from 'states/stateProvider/reducer'
import { addPopup } from 'states/stateProvider/actionCreators'
import { clearCellCache } from 'services/remote'

const GeneralSetting = ({ dispatch }: React.PropsWithoutRef<StateWithDispatch>) => {
const [t] = useTranslation()
const [clearing, setClearing] = useState(false)

const clearCache = useCallback(() => {
// TODO: real clear action
setClearing(true)
setTimeout(() => {
clearCellCache()
.catch(err => {
dispatch({
type: AppActions.AddNotification,
payload: {
type: 'alert',
timestamp: +new Date(),
content: err.message,
},
})
})
.finally(() => {
setClearing(false)
})
}, 1000)
clearCellCache().finally(() => {
addPopup('clear-cache-successfully')(dispatch)
setClearing(false)
})
}, 100)
}, [dispatch])

return (
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
"delete-wallet-successfully": "The wallet was deleted",
"create-network-successfully": "The network was created",
"update-network-successfully": "The network was updated",
"clear-cache-successfully": "The cache was cleared",
"addr-copied": "Address has been copied to the clipboard",
"qrcode-copied": "QR Code has been copied to the clipboard",
"view-the-run-node-doc": "View the guide in browser",
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
"delete-wallet-successfully": "已删除钱包",
"create-network-successfully": "已添加新节点",
"update-network-successfully": "已更新节点信息",
"clear-cache-successfully": "已清空数据缓存",
"addr-copied": "已复制地址到剪贴板",
"qrcode-copied": "已复制二维码到剪贴板",
"view-the-run-node-doc": "打开浏览器查看文档",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const initAppState = () => (dispatch: StateDispatch, history: any) => {
})
}

// text: an i18n key under `messages`
export const addPopup = (text: string) => (dispatch: StateDispatch) => {
dispatch({
type: AppActions.PopIn,
Expand Down

0 comments on commit 7dfe670

Please sign in to comment.