From 96fe3f2fe14211c1ae367800151c474e97276c7d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 2 Oct 2021 22:09:37 -0500 Subject: remove deprecated state code, update state on hub message --- src/web/src/components/App.js | 43 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index d1ce3adf..d436c326 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -3,7 +3,6 @@ import { Route, Link, Switch } from "react-router-dom"; import * as session from '../lib/session'; import * as server from '../lib/server'; -import * as application from '../lib/application'; import { createApplicationHubConnection } from '../lib/hubFactory'; @@ -33,12 +32,8 @@ const initialState = { pending: false, error: undefined }, - applicationStateInterval: undefined, applicationState: {}, error: false, - hubs: { - application: undefined, - } }; class App extends Component { @@ -55,35 +50,28 @@ class App extends Component { session.enablePassthrough() } + await session.check(); + const appHub = createApplicationHubConnection(); - appHub.on('state', (state) => console.log(state)) + appHub.on('state', (state) => { + console.debug(state) + this.setState({ applicationState: state }); + }); + appHub.start(); - await this.fetchApplicationState(); - this.setState({ login: { ...login, initialized: true }, - applicationStateInterval: window.setInterval(this.fetchApplicationState, 5000), - hubs: { - application: appHub - } }); - - await session.check(); } catch (err) { console.error(err) this.setState({ error: true }) } }; - componentWillUnmount = () => { - clearInterval(this.state.applicationStateInterval); - this.setState({ applicationStateInterval: undefined }); - }; - login = (username, password, rememberMe) => { this.setState({ login: { ...this.state.login, pending: true, error: undefined }}, async () => { try { @@ -107,25 +95,12 @@ class App extends Component { connect = async () => { await server.connect(); - this.fetchApplicationState(); }; disconnect = async () => { await server.disconnect(); - this.fetchApplicationState(); } - fetchApplicationState = async () => { - try { - this.setState({ - applicationState: await application.getState(), - error: false, - }); - } catch (err) { - this.setState({ error: err?.response?.status !== 401 }) - } - }; - render = () => { const { login, applicationState = {}, error } = this.state; const { version = {}, server } = applicationState; @@ -186,12 +161,12 @@ class App extends Component { - {server.isConnected && this.disconnect()} > Connected } - {(!server.isConnected || server.isTransitioning) && this.connect()} > -- cgit v1.2.3