2020-08-14 13:27:41 +02:00
|
|
|
import { t } from "../i18n";
|
2022-04-19 19:08:13 +02:00
|
|
|
import { useState, useEffect } from "react";
|
|
|
|
import Spinner from "./Spinner";
|
2022-09-16 18:59:03 +05:00
|
|
|
import clsx from "clsx";
|
|
|
|
import { THEME } from "../constants";
|
|
|
|
import { Theme } from "../element/types";
|
2022-04-19 19:08:13 +02:00
|
|
|
|
2022-09-16 18:59:03 +05:00
|
|
|
export const LoadingMessage: React.FC<{ delay?: number; theme?: Theme }> = ({
|
|
|
|
delay,
|
|
|
|
theme,
|
|
|
|
}) => {
|
2022-04-19 19:08:13 +02:00
|
|
|
const [isWaiting, setIsWaiting] = useState(!!delay);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!delay) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const timer = setTimeout(() => {
|
|
|
|
setIsWaiting(false);
|
|
|
|
}, delay);
|
|
|
|
return () => clearTimeout(timer);
|
|
|
|
}, [delay]);
|
|
|
|
|
|
|
|
if (isWaiting) {
|
|
|
|
return null;
|
|
|
|
}
|
2020-03-26 18:28:26 +01:00
|
|
|
|
|
|
|
return (
|
2022-09-16 18:59:03 +05:00
|
|
|
<div
|
|
|
|
className={clsx("LoadingMessage", {
|
|
|
|
"LoadingMessage--dark": theme === THEME.DARK,
|
|
|
|
})}
|
|
|
|
>
|
2022-04-19 19:08:13 +02:00
|
|
|
<div>
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
<div className="LoadingMessage-text">{t("labels.loadingScene")}</div>
|
2020-03-26 18:28:26 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|