]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/protocol/Dialog.js
svg dungeon tracker
[alttp.git] / resources / js / components / protocol / Dialog.js
1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { Alert, Button, Modal } from 'react-bootstrap';
4 import { withTranslation } from 'react-i18next';
5
6 import List from './List';
7 import i18n from '../../i18n';
8
9 class Dialog extends React.Component {
10
11         componentDidMount() {
12                 this.timer = setInterval(() => {
13                         this.forceUpdate();
14                 }, 30000);
15         }
16
17         componentWillUnmount() {
18                 clearInterval(this.timer);
19         }
20
21         render() {
22                 const {
23                         onHide,
24                         protocol,
25                         show,
26                 } = this.props;
27                 return <Modal className="protocol-dialog" onHide={onHide} show={show} size="lg">
28                         <Modal.Header closeButton>
29                                 <Modal.Title>
30                                         {i18n.t('protocol.heading')}
31                                 </Modal.Title>
32                         </Modal.Header>
33                         {protocol && protocol.length ?
34                                 <List protocol={protocol} />
35                         :
36                                 <Modal.Body>
37                                         <Alert variant="info">
38                                                 {i18n.t('protocol.empty')}
39                                         </Alert>
40                                 </Modal.Body>
41                         }
42                         <Modal.Footer>
43                                 <Button onClick={onHide} variant="secondary">
44                                         {i18n.t('button.close')}
45                                 </Button>
46                         </Modal.Footer>
47                 </Modal>;
48         }
49
50 }
51
52 Dialog.propTypes = {
53         onHide: PropTypes.func,
54         protocol: PropTypes.arrayOf(PropTypes.shape({
55                 type: PropTypes.string,
56         })),
57         show: PropTypes.bool,
58 };
59
60 Dialog.defaultProps = {
61         onHide: null,
62         protocol: null,
63         show: false,
64 };
65
66 export default withTranslation()(Dialog);