Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import React, { useContext } from 'react'
import Lottie from 'react-lottie'
import Fade from '@material-ui/core/Fade'
import { translate } from 'cozy-ui/react/I18n'
import { AppContext } from 'components/Contexts/AppContextProvider'
import StyledButton from 'components/CommonKit/Button/StyledButton'
import * as loadingData from 'assets/anims/bounceloading.json'
import * as doneData from 'assets/anims/doneloading.json'
import * as errorData from 'assets/anims/errorloading.json'
const loadingOptions = {
loop: true,
autoplay: true,
animationData: loadingData,
rendererSettings: {
preserveAspectRatio: 'xMidYMid slice',
},
}
const successOption = {
loop: false,
autoplay: true,
animationData: doneData,
rendererSettings: {
preserveAspectRatio: 'xMidYMid slice',
},
}
const errorOption = {
loop: false,
autoplay: true,
animationData: errorData,
rendererSettings: {
preserveAspectRatio: 'xMidYMid slice',
},
}
interface LoadingStepProps {
stepLabel: string
loaded: boolean | null
startCondition: boolean
}
const LoadingStep: React.FC<LoadingStepProps> = ({
stepLabel,
loaded,
startCondition,
}: LoadingStepProps) => {
return (
<div className="splash-step">
{(startCondition || loaded !== null) && (
<Fade in={startCondition} timeout={1000}>
<>
<div className="splash-step-text text-18-medium">{stepLabel}</div>
<div className="splash-step-icon">
{loaded === null ? (
<Lottie options={loadingOptions} height={50} width={50} />
) : loaded ? (
<Lottie options={successOption} height={90} width={90} />
) : (
<Lottie options={errorOption} height={90} width={90} />
)}
</div>
</>
</Fade>
)}
</div>
)
}
interface SplashContainerProps {
t: Function
}
const SplashContainer: React.FC<SplashContainerProps> = ({
t,
}: SplashContainerProps) => {
const appContext = useContext(AppContext)
return (
<div className="splash-root">
<div className="splash-header text-21-bold">{t('COMMON.APP_TITLE')}</div>
<div className="splash-content">
<LoadingStep
stepLabel={t('LOADING.INDEX')}
loaded={appContext.isIndexesLoadingSuccess}
startCondition={appContext.isIndexesLoading}
/>
<LoadingStep
stepLabel={t('LOADING.DATA')}
loaded={appContext.isDataLoadingSuccess}
startCondition={appContext.isDataLoading}
/>
<LoadingStep
stepLabel={t('LOADING.FLUIDTYPES')}
loaded={appContext.isFluidTypesLoadingSuccess}
startCondition={appContext.isFluidTypesLoading}
/>
<LoadingStep
stepLabel={t('LOADING.CHALLENGE')}
loaded={appContext.isCurrentChallengeUpdateLoadingSuccess}
startCondition={appContext.isCurrentChallengeUpdateLoading}
/>
</div>
<div className="splash-footer">
{appContext.isError && (
<>
<div className="splash-footer-error-text text-16-normal">
{t('LOADING.ERROR_LOADING')}
</div>
<StyledButton
className="splash-footer-button"
onClick={() => window.location.reload()}
>
{t('LOADING.RELOAD')}
</StyledButton>
</>
)}
</div>
</div>
)
}
export default translate()(SplashContainer)