2021-10-14 22:56:51 +05:30
|
|
|
import React, { useEffect, useState } from "react";
|
2020-06-27 12:02:54 +01:00
|
|
|
|
|
|
|
import { LoadingMessage } from "./LoadingMessage";
|
2021-02-08 15:43:51 -05:00
|
|
|
import { defaultLang, Language, languages, setLanguage } from "../i18n";
|
2020-06-27 12:02:54 +01:00
|
|
|
|
2021-01-04 02:21:52 +05:30
|
|
|
interface Props {
|
|
|
|
langCode: Language["code"];
|
2021-10-14 22:56:51 +05:30
|
|
|
children: React.ReactElement;
|
2021-01-04 02:21:52 +05:30
|
|
|
}
|
2020-06-27 12:02:54 +01:00
|
|
|
|
2021-10-14 22:56:51 +05:30
|
|
|
export const InitializeApp = (props: Props) => {
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const updateLang = async () => {
|
|
|
|
await setLanguage(currentLang);
|
|
|
|
};
|
2021-01-04 02:21:52 +05:30
|
|
|
const currentLang =
|
2021-10-14 22:56:51 +05:30
|
|
|
languages.find((lang) => lang.code === props.langCode) || defaultLang;
|
|
|
|
updateLang();
|
|
|
|
setLoading(false);
|
|
|
|
}, [props.langCode]);
|
2020-06-27 12:02:54 +01:00
|
|
|
|
2021-10-14 22:56:51 +05:30
|
|
|
return loading ? <LoadingMessage /> : props.children;
|
|
|
|
};
|