2021-05-10 19:03:42 +02:00
|
|
|
/**
|
|
|
|
* Initialization widget
|
2021-05-12 17:31:44 +02:00
|
|
|
*
|
2021-05-10 19:03:42 +02:00
|
|
|
* @author Pierre Hubert
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
2021-05-11 17:57:29 +02:00
|
|
|
import { AccountHelper } from "../../helpers/AccountHelper";
|
|
|
|
import { LoginRoute } from "../routes/LoginRoute";
|
2021-05-12 18:16:15 +02:00
|
|
|
import { MainRoute } from "../routes/MainRoute";
|
2021-05-10 19:03:42 +02:00
|
|
|
import { AsyncWidget } from "./AsyncWidget";
|
|
|
|
|
2021-05-11 17:57:29 +02:00
|
|
|
interface InitWidgetState {
|
2021-05-12 17:31:44 +02:00
|
|
|
signedIn: boolean;
|
2021-05-11 17:57:29 +02:00
|
|
|
}
|
2021-05-10 19:03:42 +02:00
|
|
|
|
2021-05-11 17:57:29 +02:00
|
|
|
export class InitWidget extends React.Component<{}, InitWidgetState> {
|
2021-05-12 17:31:44 +02:00
|
|
|
constructor(props: any) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
signedIn: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.init = this.init.bind(this);
|
|
|
|
this.build = this.build.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
async init() {
|
|
|
|
this.setState({ signedIn: false });
|
|
|
|
|
|
|
|
if (AccountHelper.hasAccessToken) {
|
|
|
|
await AccountHelper.refreshCurrentAccountInfo();
|
|
|
|
this.setState({ signedIn: true });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<AsyncWidget
|
|
|
|
errorMessage="Failed to initialize application!"
|
|
|
|
load={this.init}
|
|
|
|
onBuild={this.build}
|
|
|
|
></AsyncWidget>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
build() {
|
2021-05-12 18:16:15 +02:00
|
|
|
return this.state.signedIn ? <MainRoute /> : <LoginRoute></LoginRoute>;
|
2021-05-12 17:31:44 +02:00
|
|
|
}
|
|
|
|
}
|