Extract loading screen compontent #69

This commit is contained in:
mrdrogdrog 2020-05-24 23:58:28 +02:00 committed by GitHub
parent f185c76c6e
commit 23cfcacd09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 16 deletions

View file

@ -1,7 +1,6 @@
import React, {Fragment, useEffect, useState} from "react"; import React, {Fragment, useEffect, useState} from "react";
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
import "./application-loader.scss"; import "./application-loader.scss";
import {Alert} from "react-bootstrap"; import {LoadingScreen} from "./loading-screen";
interface ApplicationLoaderProps { interface ApplicationLoaderProps {
initTasks: Promise<any>[] initTasks: Promise<any>[]
@ -28,17 +27,9 @@ export const ApplicationLoader: React.FC<ApplicationLoaderProps> = ({children, i
}) })
}, [initTasks]); }, [initTasks]);
return (<Fragment>{ return (
doneTasks < initTasks.length || initTasks.length === 0 ? ( doneTasks < initTasks.length || initTasks.length === 0 ?
<div className="loader middle"> <LoadingScreen failed={failed}/> :
<div className="icon"> <Fragment>{children}</Fragment>
<FontAwesomeIcon icon="file-alt" size="6x" );
className={failed ? "animation-shake" : "animation-pulse"}/>
</div>
{
failed ? <Alert variant={"danger"}>An error occured while loading the application!</Alert> : null
}
</div>
) : children
}</Fragment>);
} }

View file

@ -0,0 +1,21 @@
import React from "react";
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
import {Alert} from "react-bootstrap";
export interface LoadingScreenProps {
failed: boolean
}
export const LoadingScreen: React.FC<LoadingScreenProps> = ({failed}) => {
return (
<div className="loader middle">
<div className="icon">
<FontAwesomeIcon icon="file-alt" size="6x"
className={failed ? "animation-shake" : "animation-pulse"}/>
</div>
{
failed ? <Alert variant={"danger"}>An error occured while loading the application!</Alert> : null
}
</div>
)
}