Allow setting refresh rate through url

This commit is contained in:
Gabriel Augendre 2021-11-12 17:59:14 +01:00
parent 68ea44eb02
commit 0bb97fc4a7

View file

@ -11,11 +11,17 @@ interface IAppState {
class App extends React.Component<{}, IAppState> { class App extends React.Component<{}, IAppState> {
timerId?: ReturnType<typeof setInterval>; timerId?: ReturnType<typeof setInterval>;
refreshSeconds: number;
constructor(props: {}) { constructor(props: {}) {
super(props); super(props);
this.state = {passages: [{ligne: undefined, delais: [undefined]}]}; this.state = {passages: [{ligne: undefined, delais: [undefined]}]};
this.timerId = undefined; this.timerId = undefined;
const urlParams = new URLSearchParams(window.location.search);
this.refreshSeconds = Number(urlParams.get("refreshSeconds"));
if (this.refreshSeconds <= 5) {
this.refreshSeconds = 60;
}
} }
render() { render() {
@ -42,7 +48,7 @@ class App extends React.Component<{}, IAppState> {
componentDidMount() { componentDidMount() {
this.refresh(); this.refresh();
this.timerId = setInterval(this.refresh.bind(this), 60000); this.timerId = setInterval(this.refresh.bind(this), this.refreshSeconds * 1000);
} }
componentWillUnmount() { componentWillUnmount() {