houdini/app/javascript/legacy_react/src/components/common/Root.tsx

49 lines
1.1 KiB
TypeScript
Raw Normal View History

// License: LGPL-3.0-or-later
import * as React from 'react';
2018-06-29 18:13:31 +00:00
import {observer, Provider} from 'mobx-react';
2020-06-30 21:41:47 +00:00
import {IntlProvider} from 'react-intl';
import {convert} from 'dotize'
import {ApiManager} from "../../lib/api_manager";
import {APIS} from "../../../api";
import {CSRFInterceptor} from "../../lib/csrf_interceptor";
import * as CustomAPIS from "../../lib/apis"
2020-11-24 22:20:51 +00:00
const I18n = require('../../../../i18n').default
interface RootProps
{
}
@observer
export default class Root extends React.Component<RootProps, {}> {
apiManager: ApiManager
2018-05-24 15:06:44 +00:00
componentDidMount(){
let pageProgress = (window as any).pageProgress
if (pageProgress && pageProgress.finishPageLoad){
pageProgress.finishPageLoad()
}
}
render() {
if (!this.apiManager){
this.apiManager = new ApiManager(APIS.concat(CustomAPIS.APIS as Array<any>), CSRFInterceptor)
}
return <IntlProvider locale={I18n.locale} defaultLocale={I18n.defaultLocale} messages={convert(I18n.translations[I18n.locale]) as any}>
<Provider ApiManager={this.apiManager}>
{this.props.children}
</Provider>
</IntlProvider>
}
}