From 0bb97fc4a7ca20478c18ca9ab07f092ae3f490b0 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Fri, 12 Nov 2021 17:59:14 +0100 Subject: [PATCH] Allow setting refresh rate through url --- src/App.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/App.tsx b/src/App.tsx index a1f3d90..1f5cd9c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -11,11 +11,17 @@ interface IAppState { class App extends React.Component<{}, IAppState> { timerId?: ReturnType; + refreshSeconds: number; constructor(props: {}) { super(props); this.state = {passages: [{ligne: undefined, delais: [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() { @@ -42,7 +48,7 @@ class App extends React.Component<{}, IAppState> { componentDidMount() { this.refresh(); - this.timerId = setInterval(this.refresh.bind(this), 60000); + this.timerId = setInterval(this.refresh.bind(this), this.refreshSeconds * 1000); } componentWillUnmount() {