Add refresh date in footer

This commit is contained in:
Gabriel Augendre 2021-11-12 18:04:38 +01:00
parent 0bb97fc4a7
commit ed3df67585

View file

@ -7,6 +7,7 @@ import {setInterval} from "timers";
interface IAppState { interface IAppState {
passages: ILigne[]; passages: ILigne[];
refreshDate?: string;
} }
class App extends React.Component<{}, IAppState> { class App extends React.Component<{}, IAppState> {
@ -15,13 +16,13 @@ class App extends React.Component<{}, IAppState> {
constructor(props: {}) { constructor(props: {}) {
super(props); super(props);
this.state = {passages: [{ligne: undefined, delais: [undefined]}]};
this.timerId = undefined; this.timerId = undefined;
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
this.refreshSeconds = Number(urlParams.get("refreshSeconds")); this.refreshSeconds = Number(urlParams.get("refreshSeconds"));
if (this.refreshSeconds <= 5) { if (this.refreshSeconds <= 5) {
this.refreshSeconds = 60; this.refreshSeconds = 60;
} }
this.state = {passages: [{ligne: undefined, delais: [undefined]}]};
} }
render() { render() {
@ -40,7 +41,7 @@ class App extends React.Component<{}, IAppState> {
<footer> <footer>
<p className="container"> <p className="container">
{process.env.REACT_APP_VERSION} built on {process.env.REACT_APP_DATE} {process.env.REACT_APP_VERSION} built on {process.env.REACT_APP_DATE}. Refreshed: {this.state.refreshDate}.
</p> </p>
</footer> </footer>
</div>; </div>;
@ -61,6 +62,7 @@ class App extends React.Component<{}, IAppState> {
const headers = new Headers(); const headers = new Headers();
headers.set("Authorization", `Basic ${process.env.REACT_APP_TCL_AUTH}`); headers.set("Authorization", `Basic ${process.env.REACT_APP_TCL_AUTH}`);
http<IAppState>("https://tcl.augendre.info/stop/290", {method: "GET", headers: headers}).then(json => { http<IAppState>("https://tcl.augendre.info/stop/290", {method: "GET", headers: headers}).then(json => {
json.refreshDate = new Date().toLocaleString("fr-fr");
this.setState(json); this.setState(json);
}); });
} }