Skip to content

Commit cd82ca4

Browse files
committed
feat: Different stage status of checking updates
1 parent 98fe06c commit cd82ca4

3 files changed

Lines changed: 92 additions & 20 deletions

File tree

packages/neuron-ui/src/components/GeneralSetting/index.tsx

Lines changed: 79 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,79 @@
11
import React, { useCallback, useState } from 'react'
22
import { useTranslation } from 'react-i18next'
3-
import { Stack, PrimaryButton, Spinner, Text } from 'office-ui-fabric-react'
3+
import { Stack, PrimaryButton, Spinner, Text, ProgressIndicator } from 'office-ui-fabric-react'
44
import { StateWithDispatch } from 'states/stateProvider/reducer'
55
import { addPopup } from 'states/stateProvider/actionCreators'
66
import { checkForUpdates, clearCellCache } from 'services/remote'
77

8+
const UpdateDownloadStatus = ({
9+
progress = 0,
10+
newVersion = '',
11+
}: React.PropsWithoutRef<{ progress: number; newVersion: string }>) => {
12+
const [t] = useTranslation()
13+
const available = newVersion !== '' && progress <= 0
14+
const downloaded = progress >= 1
15+
16+
if (available) {
17+
return (
18+
<Stack>
19+
<Text as="p" variant="medium">
20+
{t('updates.updates-found-do-you-want-to-update', { version: newVersion })}
21+
</Text>
22+
<Stack horizontal horizontalAlign="start">
23+
<PrimaryButton
24+
styles={{
25+
root: {
26+
minWidth: 180,
27+
},
28+
}}
29+
>
30+
{t('updates.download-update')}
31+
</PrimaryButton>
32+
</Stack>
33+
</Stack>
34+
)
35+
}
36+
37+
if (downloaded) {
38+
return (
39+
<Stack>
40+
<Text as="p" variant="medium">
41+
{t('updates.updates-downloaded-about-to-quit-and-install')}
42+
</Text>
43+
<Stack horizontal horizontalAlign="start">
44+
<PrimaryButton
45+
styles={{
46+
root: {
47+
minWidth: 180,
48+
},
49+
}}
50+
>
51+
{t('updates.quit-and-install')}
52+
</PrimaryButton>
53+
</Stack>
54+
</Stack>
55+
)
56+
}
57+
58+
return (
59+
<ProgressIndicator
60+
percentComplete={progress}
61+
label={t('updates.downloading-update')}
62+
styles={{ root: { width: '250px' } }}
63+
/>
64+
)
65+
}
66+
867
const GeneralSetting = ({ dispatch }: React.PropsWithoutRef<StateWithDispatch>) => {
968
const [t] = useTranslation()
1069
const [clearing, setClearing] = useState(false)
1170
const [checkingUpdates, setCheckingUpdates] = useState(false) // TODO: checkingUpdates should be fetched from backend
71+
const [downloadingUpdate] = useState(false)
1272

1373
const checkUpdates = useCallback(() => {
1474
setCheckingUpdates(true)
1575
setTimeout(() => {
16-
checkForUpdates().finally(() => {
17-
setCheckingUpdates(false)
18-
})
76+
checkForUpdates()
1977
}, 100)
2078
}, [dispatch])
2179

@@ -33,18 +91,22 @@ const GeneralSetting = ({ dispatch }: React.PropsWithoutRef<StateWithDispatch>)
3391
<Stack tokens={{ childrenGap: 15 }}>
3492
<Stack>
3593
<Stack horizontal horizontalAlign="start">
36-
<PrimaryButton
37-
onClick={checkUpdates}
38-
disabled={checkingUpdates}
39-
ariaDescription="Check updates"
40-
styles={{
41-
root: {
42-
minWidth: 150,
43-
},
44-
}}
45-
>
46-
{checkingUpdates ? <Spinner /> : t('updates.check-updates')}
47-
</PrimaryButton>
94+
{downloadingUpdate ? (
95+
<UpdateDownloadStatus progress={1} newVersion="v0.25.2" />
96+
) : (
97+
<PrimaryButton
98+
onClick={checkUpdates}
99+
disabled={checkingUpdates}
100+
ariaDescription="Check updates"
101+
styles={{
102+
root: {
103+
minWidth: 180,
104+
},
105+
}}
106+
>
107+
{checkingUpdates ? <Spinner /> : t('updates.check-updates')}
108+
</PrimaryButton>
109+
)}
48110
</Stack>
49111
</Stack>
50112

@@ -59,7 +121,7 @@ const GeneralSetting = ({ dispatch }: React.PropsWithoutRef<StateWithDispatch>)
59121
ariaDescription="Clear cache"
60122
styles={{
61123
root: {
62-
minWidth: 150,
124+
minWidth: 180,
63125
},
64126
}}
65127
>

packages/neuron-ui/src/locales/en.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
"network": "Network"
179179
},
180180
"general": {
181-
"clear-cache": "Clear cache",
181+
"clear-cache": "Clear Cache",
182182
"clear-cache-description": "Clear cache if you encounter data sync or balance display problems. Neuron will rescan block data.",
183183
"show": "Show",
184184
"hide": "Hide"
@@ -346,7 +346,12 @@
346346
},
347347
"updates": {
348348
"check-updates": "Check for Updates",
349-
"download-update": "Download Update"
349+
"downloading-update": "Downloading update...",
350+
"update-not-available": "There are currently no updates available.",
351+
"updates-found-do-you-want-to-update": "An update ({{version}}) is available, do you want to download and update now?",
352+
"download-update": "Download Update",
353+
"updates-downloaded-about-to-quit-and-install": "Update downloaded. Neuron will quit and install the update...",
354+
"quit-and-install": "Quit and Install"
350355
}
351356
}
352357
}

packages/neuron-ui/src/locales/zh.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,12 @@
346346
},
347347
"updates": {
348348
"check-updates": "检查更新",
349-
"download-update": "下载更新"
349+
"downloading-update": "正在下载更新...",
350+
"update-not-available": "没有可供升级的新版本。",
351+
"updates-found-do-you-want-to-update": "有可供升级的新版本({{version}})。现在进行下载和升级吗?",
352+
"download-update": "下载更新以升级",
353+
"updates-downloaded-about-to-quit-and-install": "下载完成。Neuron 将退出并安装新版本...",
354+
"quit-and-install": "退出并安装"
350355
}
351356
}
352357
}

0 commit comments

Comments
 (0)