Skip to content

Commit

Permalink
Cleanup/improve Connection Lost Dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
jbflo authored and marcus-oscarsson committed Feb 14, 2025
1 parent e91f3f0 commit 0b15649
Showing 1 changed file with 21 additions and 83 deletions.
104 changes: 21 additions & 83 deletions ui/src/containers/ConnectionLostDialog.jsx
Original file line number Diff line number Diff line change
@@ -1,88 +1,26 @@
/* eslint-disable react/jsx-handler-names */
/* eslint-disable react/no-string-refs */
import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { useSelector } from 'react-redux';
import { Modal, Button } from 'react-bootstrap';
import { showConnectionLostDialog } from '../actions/general';

export class ConnectionLostDialog extends React.Component {
constructor(props) {
super(props);
this.accept = this.accept.bind(this);
this.reject = this.reject.bind(this);
this.intervalCb = this.intervalCb.bind(this);
this.seconds = 60;
this.timerid = undefined;
}

intervalCb() {
this.seconds--;

if (this.refs.countdown) {
this.refs.countdown.innerHTML = this.seconds;
}

if (this.seconds < 1) {
this.seconds = 0;
this.accept();
}
}

accept() {
this.forceUpdate();
}

reject() {
this.props.hide();
}

render() {
this.seconds = 60;

if (this.timerid) {
clearInterval(this.timerid);
}

this.timerid = setInterval(this.intervalCb, 1000);
setTimeout(() => {
clearInterval(this.timerid);
}, this.seconds * 1000);

return (
<Modal show={this.props.show} onHide={this.props.hide}>
<Modal.Header>
<Modal.Title>Connection lost</Modal.Title>
</Modal.Header>
<Modal.Body>
Ooops ! There seems to be a problem with the internet connection, the
connection to the server was lost. Trying to reconnect in{' '}
<span ref="countdown">{this.seconds}</span> s
</Modal.Body>
<Modal.Footer>
<Button onClick={this.accept}> Try again </Button>
</Modal.Footer>
</Modal>
);
}
}

function mapStateToProps(state) {
return {
show: state.general.showConnectionLostDialog,
};
}

function mapDispatchToProps(dispatch) {
return {
hide: bindActionCreators(
showConnectionLostDialog.bind(null, false),
dispatch,
),
};
export function ConnectionLostDialog() {
const show = useSelector((state) => state.general.showConnectionLostDialog);

return (
<Modal show={show}>
<Modal.Header>
<Modal.Title>Connection lost</Modal.Title>
</Modal.Header>
<Modal.Body>
Trying to reconnect now...
<br />
If the issue persists, please check your Internet connection or reload
the page.
</Modal.Body>
<Modal.Footer>
<Button onClick={() => window.location.reload(true)}> Reload </Button>
</Modal.Footer>
</Modal>
);
}

export default connect(
mapStateToProps,
mapDispatchToProps,
)(ConnectionLostDialog);
export default ConnectionLostDialog;

0 comments on commit 0b15649

Please sign in to comment.