Files
mattermostest/src/browser/components/LoadingScreen.jsx
Dean Whillier 83bae0c2b8 [MM-22810] Update loading screen with new design & animation (#1409)
* Update loading screen with new design & animation

* add prop back in

* adjust z-index for tests

* tweaks to pass tests

* address offline feedback

- shrink initial logo size
- introduce a slight delay before fading loading spinner out
- fix horizontal scrollbar showing on load screen

* add missing css variable

* no need to remove loading icon

* Apply suggestions from code review

Co-authored-by: Guillermo Vayá <guillermo.vaya@mattermost.com>

* Move LoadingScreen.jsx to file-only component

* Rename prop for better clarity

* Default prop to none and check when needed

* Update import paths

* Add ESDocs and remove unecessary conditional

* Forgot to remove the eslint override

Co-authored-by: Guillermo Vayá <guillermo.vaya@mattermost.com>
2020-11-17 15:13:03 +01:00

76 lines
2.1 KiB
JavaScript

// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import useTransitionEnd from '../hooks/useTransitionEnd.js';
import LoadingAnimation from './LoadingAnimation';
/**
* A function component for rendering the desktop app loading screen
* @param {boolean} loading - Prop that indicates whether currently loading or not
* @param {boolean} darkMode - Prop that indicates if dark mode is enabled
*/
function LoadingScreen({loading = false, darkMode = false}) {
const loadingScreenRef = React.useRef(null);
const [loadingIsComplete, setLoadingIsComplete] = React.useState(true);
const [loadAnimationIsComplete, setLoadAnimationIsComplete] = React.useState(true);
const [fadeOutIsComplete, setFadeOutIsComplete] = React.useState(true);
React.useEffect(() => {
// reset internal state if loading restarts
if (loading) {
resetState();
} else {
setLoadingIsComplete(true);
}
}, [loading]);
function handleLoadAnimationComplete() {
setLoadAnimationIsComplete(true);
}
useTransitionEnd(loadingScreenRef, React.useCallback(() => {
setFadeOutIsComplete(true);
}), ['opacity']);
function loadingInProgress() {
return !(loadingIsComplete && loadAnimationIsComplete && fadeOutIsComplete);
}
function resetState() {
setLoadingIsComplete(false);
setLoadAnimationIsComplete(false);
setFadeOutIsComplete(false);
}
const loadingScreen = (
<div
ref={loadingScreenRef}
className={classNames('LoadingScreen', {
'LoadingScreen--darkMode': darkMode,
'LoadingScreen--loaded': loadingIsComplete && loadAnimationIsComplete,
})}
>
<LoadingAnimation
loading={loading}
darkMode={darkMode}
onLoadAnimationComplete={handleLoadAnimationComplete}
/>
</div>
);
return loadingInProgress() ? loadingScreen : null;
}
LoadingScreen.propTypes = {
loading: PropTypes.bool,
darkMode: PropTypes.bool,
};
export default LoadingScreen;