aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-10-02 22:09:37 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-10-02 22:09:37 -0500
commit96fe3f2fe14211c1ae367800151c474e97276c7d (patch)
tree0cf1735160105f6eb07b482ceda9a1dffe984b6c /src
parentebe27d87632691898a5116985474a14b28365e14 (diff)
downloadslskd-96fe3f2fe14211c1ae367800151c474e97276c7d.tar.gz
remove deprecated state code, update state on hub message
Diffstat (limited to 'src')
-rw-r--r--src/web/src/components/App.js43
1 files changed, 9 insertions, 34 deletions
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 {
</Menu.Item>
</Link>
<Menu className='right' inverted>
- {server.isConnected && <Menu.Item
+ {server?.isConnected && <Menu.Item
onClick={() => this.disconnect()}
>
<Icon name='plug' color='green'/>Connected
</Menu.Item>}
- {(!server.isConnected || server.isTransitioning) && <Menu.Item
+ {(!server?.isConnected || server?.isTransitioning) && <Menu.Item
onClick={() => this.connect()}
>
<Icon.Group className='menu-icon-group'>