2020-06-27 12:02:54 +01:00
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
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"];
|
|
|
|
}
|
|
|
|
interface State {
|
|
|
|
isLoading: boolean;
|
|
|
|
}
|
|
|
|
export class InitializeApp extends React.Component<Props, State> {
|
2020-06-27 12:02:54 +01:00
|
|
|
public state: { isLoading: boolean } = {
|
|
|
|
isLoading: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
async componentDidMount() {
|
2021-01-04 02:21:52 +05:30
|
|
|
const currentLang =
|
|
|
|
languages.find((lang) => lang.code === this.props.langCode) ||
|
|
|
|
defaultLang;
|
2021-02-08 15:43:51 -05:00
|
|
|
await setLanguage(currentLang);
|
2020-06-27 12:02:54 +01:00
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
return this.state.isLoading ? <LoadingMessage /> : this.props.children;
|
|
|
|
}
|
|
|
|
}
|