You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
768 B
TypeScript
28 lines
768 B
TypeScript
3 years ago
|
import React, { useEffect, useState } from "react";
|
||
5 years ago
|
|
||
|
import { LoadingMessage } from "./LoadingMessage";
|
||
4 years ago
|
import { defaultLang, Language, languages, setLanguage } from "../i18n";
|
||
2 years ago
|
import { Theme } from "../element/types";
|
||
5 years ago
|
|
||
4 years ago
|
interface Props {
|
||
|
langCode: Language["code"];
|
||
3 years ago
|
children: React.ReactElement;
|
||
2 years ago
|
theme?: Theme;
|
||
4 years ago
|
}
|
||
5 years ago
|
|
||
3 years ago
|
export const InitializeApp = (props: Props) => {
|
||
|
const [loading, setLoading] = useState(true);
|
||
|
|
||
|
useEffect(() => {
|
||
|
const updateLang = async () => {
|
||
|
await setLanguage(currentLang);
|
||
3 years ago
|
setLoading(false);
|
||
3 years ago
|
};
|
||
4 years ago
|
const currentLang =
|
||
3 years ago
|
languages.find((lang) => lang.code === props.langCode) || defaultLang;
|
||
|
updateLang();
|
||
|
}, [props.langCode]);
|
||
5 years ago
|
|
||
2 years ago
|
return loading ? <LoadingMessage theme={props.theme} /> : props.children;
|
||
3 years ago
|
};
|