-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3233 from JoinColony/feat/3229-loading-delay-failing
Add LoadingTemplate delayed/failed updates
- Loading branch information
Showing
4 changed files
with
169 additions
and
17 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/modules/pages/components/LoadingTemplate/LoadingTemplate.css.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export const main: string; | ||
export const mainContent: string; | ||
export const loaderContainer: string; | ||
export const loadingDelayedOrFailed: string; | ||
export const loadingDelayedOrFailedDetail: string; | ||
export const nakedMole: string; |
111 changes: 94 additions & 17 deletions
111
src/modules/pages/components/LoadingTemplate/LoadingTemplate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,106 @@ | ||
import React, { ReactNode } from 'react'; | ||
import { MessageDescriptor } from 'react-intl'; | ||
import React, { ReactNode, useEffect, useState } from 'react'; | ||
import { MessageDescriptor, defineMessages, useIntl } from 'react-intl'; | ||
|
||
import { SpinnerLoader } from '~core/Preloaders'; | ||
|
||
import NakedMole from '../../../../img/naked-mole-without-bg.svg'; | ||
import styles from './LoadingTemplate.css'; | ||
|
||
interface Props { | ||
children?: ReactNode; | ||
loadingText?: string | MessageDescriptor; | ||
} | ||
|
||
const LoadingTemplate = ({ children, loadingText }: Props) => ( | ||
<div className={styles.main}> | ||
<main className={styles.mainContent}> | ||
<div> | ||
<div className={styles.loaderContainer}> | ||
<SpinnerLoader | ||
loadingText={loadingText} | ||
appearance={{ theme: 'primary', size: 'massive' }} | ||
/> | ||
</div> | ||
{children} | ||
</div> | ||
</main> | ||
</div> | ||
); | ||
const MSG = defineMessages({ | ||
loadingDelayed: { | ||
id: 'pages.LoadingTemplate.loadingDelayed', | ||
defaultMessage: `As you can see, it's taking a while to connect to the service.`, | ||
}, | ||
|
||
loadingDelayedDescription: { | ||
id: 'pages.LoadingTemplate.loadingDelayedDescription', | ||
defaultMessage: `Please hold tight while we keep trying. Sorry, we know this is boring.`, | ||
}, | ||
|
||
loadingFailed: { | ||
id: 'pages.LoadingTemplate.loadingFailed', | ||
defaultMessage: `Oh noes! We tried and tried but | ||
couldn't get any response from the service.`, | ||
}, | ||
|
||
loadingFailedDescription: { | ||
id: 'pages.LoadingTemplate.loadingFailedDescription', | ||
defaultMessage: `We're probably already trying to fix this, so please try again later.`, | ||
}, | ||
}); | ||
|
||
const delayedLoadingDuration = 15 * 1000; // 15 seconds | ||
const failedLoadingDuration = 30 * 1000; // 30 seconds | ||
|
||
const LoadingTemplate = ({ children, loadingText }: Props) => { | ||
type LoadingStateType = 'default' | 'delayed' | 'failed'; | ||
const [loadingState, setLoadingState] = useState<LoadingStateType>('default'); | ||
|
||
useEffect(() => { | ||
const delayTimer = setTimeout(() => { | ||
setLoadingState('delayed'); | ||
}, delayedLoadingDuration); | ||
return () => clearTimeout(delayTimer); | ||
}, []); | ||
|
||
useEffect(() => { | ||
const failedTimer = setTimeout(() => { | ||
setLoadingState('failed'); | ||
}, failedLoadingDuration); | ||
return () => clearTimeout(failedTimer); | ||
}, []); | ||
|
||
const { formatMessage } = useIntl(); | ||
|
||
return ( | ||
<div className={styles.main}> | ||
<main className={styles.mainContent}> | ||
{loadingState !== 'failed' && ( | ||
<div> | ||
<div className={styles.loaderContainer}> | ||
<SpinnerLoader | ||
loadingText={loadingText} | ||
appearance={{ theme: 'primary', size: 'massive' }} | ||
/> | ||
</div> | ||
{children} | ||
</div> | ||
)} | ||
|
||
{loadingState === 'failed' && ( | ||
<div className={styles.loaderContainer}> | ||
<div className={styles.nakedMole}> | ||
<NakedMole /> | ||
</div> | ||
</div> | ||
)} | ||
|
||
{loadingState !== 'default' && ( | ||
<div> | ||
<div className={styles.loadingDelayedOrFailed}> | ||
<p> | ||
{loadingState === 'delayed' | ||
? formatMessage(MSG.loadingDelayed) | ||
: formatMessage(MSG.loadingFailed)} | ||
</p> | ||
<div className={styles.loadingDelayedOrFailedDetail}> | ||
<p> | ||
{loadingState === 'delayed' | ||
? formatMessage(MSG.loadingDelayedDescription) | ||
: formatMessage(MSG.loadingFailedDescription)} | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
)} | ||
</main> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LoadingTemplate; |