Skip to content

Commit

Permalink
fix: Don't render LoadingSpinner after it has faded out (#5164)
Browse files Browse the repository at this point in the history
  • Loading branch information
jviide authored and mythsunwind committed Nov 25, 2021
1 parent d2cb074 commit ce413c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions electron/renderer/src/components/LoadingSpinner.css
Expand Up @@ -19,6 +19,7 @@

.loading-spinner-wrapper {
height: 100vh;
display: flex;
position: absolute;
width: 100%;
z-index: 2;
Expand Down
22 changes: 21 additions & 1 deletion electron/renderer/src/components/LoadingSpinner.jsx
Expand Up @@ -22,8 +22,11 @@ import {FlexBox, Loading, COLOR} from '@wireapp/react-ui-kit';

import './LoadingSpinner.css';

const TRANSITION_GRACE_PERIOD_MS = 500;

const LoadingSpinner = ({visible, webviewRef}) => {
const [isLoading, setIsLoading] = useState(true);
const [isFinished, setIsFinished] = useState(false);

useEffect(() => {
const webview = webviewRef.current;
Expand All @@ -37,13 +40,30 @@ const LoadingSpinner = ({visible, webviewRef}) => {
}
});

useEffect(() => {
if (!isLoading) {
let timeout = setTimeout(() => {
timeout = null;
setIsFinished(true);
}, TRANSITION_GRACE_PERIOD_MS);

return () => {
if (timeout !== null) {
clearTimeout(timeout);
}
};
}
}, [isLoading]);

if (!visible || isFinished) {
return null;
}
return (
<div
className="loading-spinner-wrapper"
data-uie-name="loading-spinner-wrapper"
style={{
backgroundColor: COLOR.GRAY_LIGHTEN_88,
display: visible ? 'flex' : 'none',
opacity: isLoading ? 1 : 0,
pointerEvents: isLoading ? 'all' : 'none',
}}
Expand Down

0 comments on commit ce413c1

Please sign in to comment.