11import React , { useCallback , useState } from 'react'
22import { 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'
44import { StateWithDispatch } from 'states/stateProvider/reducer'
55import { addPopup } from 'states/stateProvider/actionCreators'
66import { 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+
867const 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 >
0 commit comments