-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathChartModal.jsx
58 lines (50 loc) · 1.72 KB
/
ChartModal.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';
function ChartModal(props) {
const { type, setShowModal, trainName, offsetTimeByDragging } = props;
const { t } = useTranslation(['simulation']);
const [offset, setOffset] = useState('');
// ADN: just do an upadteSimulation, should do the rest
const sendOffset = ({ key }) => {
if (key === 'Enter') {
setShowModal('');
const seconds = parseInt(type === '-' ? offset * -1 : offset, 10);
offsetTimeByDragging(seconds);
}
};
useEffect(() => {
window.addEventListener('keydown', sendOffset);
return () => {
window.removeEventListener('keydown', sendOffset);
};
}, [offset]);
return (
<div className="osrd-simulation-chart-modal">
<div className="chart-modal-box">
<div className="chart-modal-type-title">
<span className="mr-1">{t('simulation:ManualOffset')}</span>
{trainName}
</div>
<div className="chart-modal-input">
<div className="chart-modal-type-label">{type}</div>
<input
type="string"
autoFocus // eslint-disable-line jsx-a11y/no-autofocus
onBlur={() => setShowModal('')}
onChange={(e) => setOffset(e.target.value.replace(/\D/g, ''))} // Filter non digit chars
value={offset}
/>
<div className="chart-modal-type-unit">s</div>
</div>
</div>
</div>
);
}
ChartModal.propTypes = {
type: PropTypes.string.isRequired,
trainName: PropTypes.string.isRequired,
setShowModal: PropTypes.func.isRequired,
offsetTimeByDragging: PropTypes.func.isRequired,
};
export default ChartModal;