SoapboxMount: display a spinner while API requests are loading

environments/review-develop-3zknud/deployments/22^2
Alex Gleason 2 years ago
parent b3d2306aaf
commit 93187c8eed
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

@ -1,9 +1,9 @@
/** /**
* iOS style loading spinner. * iOS style loading spinner.
* Adapted from: https://loading.io/css/ * Adapted from: https://loading.io/css/
* With some help scaling it: https://signalvnoise.com/posts/2577-loading-spinner-animation-using-css-and-webkit * With some help scaling it: https://signalvnoise.com/posts/2577-loading-spinner-animation-using-css-and-webkit
*/ */
.spinner { .spinner {
@apply inline-block relative w-20 h-20; @apply inline-block relative w-20 h-20;
} }

@ -6,7 +6,7 @@ import Text from '../text/text';
import './spinner.css'; import './spinner.css';
interface ILoadingIndicator { interface ISpinner {
/** Width and height of the spinner in pixels. */ /** Width and height of the spinner in pixels. */
size?: number, size?: number,
/** Whether to display "Loading..." beneath the spinner. */ /** Whether to display "Loading..." beneath the spinner. */
@ -14,7 +14,7 @@ interface ILoadingIndicator {
} }
/** Spinning loading placeholder. */ /** Spinning loading placeholder. */
const LoadingIndicator = ({ size = 30, withText = true }: ILoadingIndicator) => ( const Spinner = ({ size = 30, withText = true }: ISpinner) => (
<Stack space={2} justifyContent='center' alignItems='center'> <Stack space={2} justifyContent='center' alignItems='center'>
<div className='spinner' style={{ width: size, height: size }}> <div className='spinner' style={{ width: size, height: size }}>
{Array.from(Array(12).keys()).map(i => ( {Array.from(Array(12).keys()).map(i => (
@ -30,4 +30,4 @@ const LoadingIndicator = ({ size = 30, withText = true }: ILoadingIndicator) =>
</Stack> </Stack>
); );
export default LoadingIndicator; export default Spinner;

@ -14,6 +14,7 @@ import { loadSoapboxConfig, getSoapboxConfig } from 'soapbox/actions/soapbox';
import { fetchVerificationConfig } from 'soapbox/actions/verification'; import { fetchVerificationConfig } from 'soapbox/actions/verification';
import * as BuildConfig from 'soapbox/build_config'; import * as BuildConfig from 'soapbox/build_config';
import Helmet from 'soapbox/components/helmet'; import Helmet from 'soapbox/components/helmet';
import { Spinner } from 'soapbox/components/ui';
import AuthLayout from 'soapbox/features/auth_layout'; import AuthLayout from 'soapbox/features/auth_layout';
import OnboardingWizard from 'soapbox/features/onboarding/onboarding-wizard'; import OnboardingWizard from 'soapbox/features/onboarding/onboarding-wizard';
import PublicLayout from 'soapbox/features/public_layout'; import PublicLayout from 'soapbox/features/public_layout';
@ -115,10 +116,25 @@ const SoapboxMount = () => {
return !(location.state?.soapboxModalKey && location.state?.soapboxModalKey !== prevRouterProps?.location?.state?.soapboxModalKey); return !(location.state?.soapboxModalKey && location.state?.soapboxModalKey !== prevRouterProps?.location?.state?.soapboxModalKey);
}; };
if (me === null) return null; /** Whether to display a loading indicator. */
if (me && !account) return null; const showLoading = [
if (!isLoaded) return null; me === null,
if (localeLoading) return null; me && !account,
!isLoaded,
localeLoading,
].some(Boolean);
if (showLoading) {
return (
<div className='p-4 h-screen w-screen flex items-center justify-center'>
<Helmet>
{themeCss && <style id='theme' type='text/css'>{`:root{${themeCss}}`}</style>}
</Helmet>
<Spinner size={40} withText={false} />
</div>
);
}
const waitlisted = account && !account.source.get('approved', true); const waitlisted = account && !account.source.get('approved', true);

Loading…
Cancel
Save