aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/App.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/components/App.js')
-rw-r--r--frontend/src/components/App.js29
1 files changed, 18 insertions, 11 deletions
diff --git a/frontend/src/components/App.js b/frontend/src/components/App.js
index e12a99d..96083cd 100644
--- a/frontend/src/components/App.js
+++ b/frontend/src/components/App.js
@@ -16,6 +16,7 @@
*/
import React, {Component} from "react";
+import {BrowserRouter as Router} from "react-router-dom";
import dispatcher from "../dispatcher";
import Notifications from "./Notifications";
import ConfigurationPage from "./pages/ConfigurationPage";
@@ -27,15 +28,7 @@ class App extends Component {
state = {};
componentDidMount() {
- dispatcher.register("notifications", (payload) => {
- if (payload.event === "connected") {
- this.setState({
- connected: true,
- configured: payload.message["is_configured"],
- version: payload.message["version"]
- });
- }
- });
+ dispatcher.register("notifications", this.handleNotifications);
setInterval(() => {
if (document.title.endsWith("❚")) {
@@ -46,16 +39,30 @@ class App extends Component {
}, 500);
}
+ componentWillUnmount() {
+ dispatcher.unregister(this.handleNotifications);
+ }
+
+ handleNotifications = (payload) => {
+ if (payload.event === "connected") {
+ this.setState({
+ connected: true,
+ configured: payload.message["is_configured"],
+ version: payload.message["version"]
+ });
+ }
+ };
+
render() {
return (
- <>
+ <Router>
<Notifications/>
{this.state.connected ?
(this.state.configured ? <MainPage version={this.state.version}/> :
<ConfigurationPage onConfigured={() => this.setState({configured: true})}/>) :
<ServiceUnavailablePage/>
}
- </>
+ </Router>
);
}
}