|
1 |
| -/* eslint-disable react/jsx-handler-names */ |
2 |
| -/* eslint-disable react/no-string-refs */ |
3 | 1 | import React from 'react';
|
4 |
| -import { connect } from 'react-redux'; |
5 |
| -import { bindActionCreators } from 'redux'; |
| 2 | +import { useSelector } from 'react-redux'; |
6 | 3 | import { Modal, Button } from 'react-bootstrap';
|
7 |
| -import { showConnectionLostDialog } from '../actions/general'; |
8 | 4 |
|
9 |
| -export class ConnectionLostDialog extends React.Component { |
10 |
| - constructor(props) { |
11 |
| - super(props); |
12 |
| - this.accept = this.accept.bind(this); |
13 |
| - this.reject = this.reject.bind(this); |
14 |
| - this.intervalCb = this.intervalCb.bind(this); |
15 |
| - this.seconds = 60; |
16 |
| - this.timerid = undefined; |
17 |
| - } |
18 |
| - |
19 |
| - intervalCb() { |
20 |
| - this.seconds--; |
21 |
| - |
22 |
| - if (this.refs.countdown) { |
23 |
| - this.refs.countdown.innerHTML = this.seconds; |
24 |
| - } |
25 |
| - |
26 |
| - if (this.seconds < 1) { |
27 |
| - this.seconds = 0; |
28 |
| - this.accept(); |
29 |
| - } |
30 |
| - } |
31 |
| - |
32 |
| - accept() { |
33 |
| - this.forceUpdate(); |
34 |
| - } |
35 |
| - |
36 |
| - reject() { |
37 |
| - this.props.hide(); |
38 |
| - } |
39 |
| - |
40 |
| - render() { |
41 |
| - this.seconds = 60; |
42 |
| - |
43 |
| - if (this.timerid) { |
44 |
| - clearInterval(this.timerid); |
45 |
| - } |
46 |
| - |
47 |
| - this.timerid = setInterval(this.intervalCb, 1000); |
48 |
| - setTimeout(() => { |
49 |
| - clearInterval(this.timerid); |
50 |
| - }, this.seconds * 1000); |
51 |
| - |
52 |
| - return ( |
53 |
| - <Modal show={this.props.show} onHide={this.props.hide}> |
54 |
| - <Modal.Header> |
55 |
| - <Modal.Title>Connection lost</Modal.Title> |
56 |
| - </Modal.Header> |
57 |
| - <Modal.Body> |
58 |
| - Ooops ! There seems to be a problem with the internet connection, the |
59 |
| - connection to the server was lost. Trying to reconnect in{' '} |
60 |
| - <span ref="countdown">{this.seconds}</span> s |
61 |
| - </Modal.Body> |
62 |
| - <Modal.Footer> |
63 |
| - <Button onClick={this.accept}> Try again </Button> |
64 |
| - </Modal.Footer> |
65 |
| - </Modal> |
66 |
| - ); |
67 |
| - } |
68 |
| -} |
69 |
| - |
70 |
| -function mapStateToProps(state) { |
71 |
| - return { |
72 |
| - show: state.general.showConnectionLostDialog, |
73 |
| - }; |
74 |
| -} |
75 |
| - |
76 |
| -function mapDispatchToProps(dispatch) { |
77 |
| - return { |
78 |
| - hide: bindActionCreators( |
79 |
| - showConnectionLostDialog.bind(null, false), |
80 |
| - dispatch, |
81 |
| - ), |
82 |
| - }; |
| 5 | +export function ConnectionLostDialog() { |
| 6 | + const show = useSelector((state) => state.general.showConnectionLostDialog); |
| 7 | + |
| 8 | + return ( |
| 9 | + <Modal show={show}> |
| 10 | + <Modal.Header> |
| 11 | + <Modal.Title>Connection lost</Modal.Title> |
| 12 | + </Modal.Header> |
| 13 | + <Modal.Body> |
| 14 | + Trying to reconnect now... |
| 15 | + <br /> |
| 16 | + If the issue persists, please check your Internet connection or reload |
| 17 | + the page. |
| 18 | + </Modal.Body> |
| 19 | + <Modal.Footer> |
| 20 | + <Button onClick={() => window.location.reload(true)}> Reload </Button> |
| 21 | + </Modal.Footer> |
| 22 | + </Modal> |
| 23 | + ); |
83 | 24 | }
|
84 | 25 |
|
85 |
| -export default connect( |
86 |
| - mapStateToProps, |
87 |
| - mapDispatchToProps, |
88 |
| -)(ConnectionLostDialog); |
| 26 | +export default ConnectionLostDialog; |
0 commit comments