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
import React, { useEffect, useState } from 'react';
import { Col, Container, Row } from 'react-bootstrap';
import logo from '/public/logo.png';
interface DelayedRenderProps {
children: React.ReactNode;
loading?: {
minimumLoadingTime: number;
component: () => JSX.Element
}
}
export const SplashScreen = () => {
const [dots, setDots] = useState('');
useEffect(() => {
const dotsInterval = setInterval(() => {
setDots(prev => prev.length >= 3 ? '' : prev + '.');
}, 500);
return () => clearInterval(dotsInterval);
}, []);
return (
<div className="splash-screen-overlay">
<Container fluid className="h-100 d-flex align-items-center justify-content-center bg-bg-primary">
<Row>
<Col className="text-center">
<div className="loading-bounce mb-4">
<img
src={logo}
alt="Logo"
className="img-fluid"
style={{ width: '120px', height: '120px', objectFit: 'contain' }}
/>
</div>
<div className="loading-text">
<span className="h4 text-secondary">Loading</span>
<span className="h4 text-secondary dots-width">{dots}</span>
</div>
</Col>
</Row>
</Container>
<style>
{`
.splash-screen-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #f8f9fa;
z-index: 0;
display: flex;
align-items: center;
justify-content: center;
}
.loading-bounce {
animation: bounce 1s infinite;
}
@keyframes bounce {
0%, 100% {
transform: translateY(0);
}
50% {
transform: translateY(-20px);
}
}
.loading-text {
display: flex;
justify-content: center;
align-items: center;
}
.dots-width {
min-width: 24px;
text-align: left;
margin-left: 2px;
}
`}
</style>
</div>
);
};
export const DelayedRender: React.FC<DelayedRenderProps> = ({
children,
loading
}) => {
const [shouldRender, setShouldRender] = useState(false);
useEffect(() => {
if (!loading) {
setShouldRender(true);
return;
}
const timer = setTimeout(() => {
setShouldRender(true);
}, loading.minimumLoadingTime);
return () => clearTimeout(timer);
}, [loading]);
if (!shouldRender && loading) {
const LoadingComponent = loading.component;
return <LoadingComponent />;
}
return <>{children}</>;
};
export default DelayedRender;