-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathindex.jsx
More file actions
124 lines (105 loc) · 2.84 KB
/
Copy pathindex.jsx
File metadata and controls
124 lines (105 loc) · 2.84 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import React, { useCallback } from 'react';
import {
useDispatch,
useSelector,
} from 'react-redux';
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';
import GenericButton from './GenericButton';
import {
prod,
show,
selectSupported,
} from '../MelodyEditor/melodiesSlice';
import {
selectCanFlash,
selectCanRead,
selectCanWrite,
setSelecting,
} from '../../Containers/App/stateSlice';
import {
selectIndividual,
setTargets,
} from '../../Containers/App/escsSlice';
import './style.scss';
function Buttonbar({
onReadSetup,
onWriteSetup,
onResetDefaults,
}) {
const { t } = useTranslation('common');
const dispatch = useDispatch();
const showMelodyEditor = useSelector(selectSupported);
const canFlash = useSelector(selectCanFlash);
const canRead = useSelector(selectCanRead);
const canWrite = useSelector(selectCanWrite);
const escs = useSelector(selectIndividual);
const onSeletFirmwareForAll = useCallback(() => {
const targets = [];
for (let i = 0; i < escs.length; i += 1) {
const esc = escs[i];
targets.push(esc.index);
}
dispatch(setSelecting(true));
dispatch(setTargets(targets));
}, [dispatch, escs]);
const handleOpenMelodyEditor = useCallback(() => {
dispatch(prod());
dispatch(show());
}, [dispatch]);
return (
<div className="button-bar">
<div className="buttons-bottom mobile-show">
{showMelodyEditor &&
<GenericButton
disabled={!canRead}
onClick={handleOpenMelodyEditor}
text={t('escButtonOpenMelodyEditor')}
/>}
</div>
<div className="buttons-left">
<div className="mobile-show">
<GenericButton
disabled={!canWrite}
onClick={onResetDefaults}
text={t('resetDefaults')}
/>
</div>
</div>
<div className="buttons-right">
<GenericButton
disabled={!canRead}
onClick={onReadSetup}
text={t('escButtonRead')}
/>
<GenericButton
disabled={!canWrite}
onClick={onWriteSetup}
text={t('escButtonWrite')}
/>
<GenericButton
disabled={!canFlash}
onClick={onSeletFirmwareForAll}
text={t('escButtonFlashAll')}
/>
<GenericButton
disabled={!canWrite}
onClick={onResetDefaults}
text={t('resetDefaults')}
/>
{showMelodyEditor &&
<GenericButton
disabled={!canRead}
onClick={handleOpenMelodyEditor}
text={t('escButtonOpenMelodyEditor')}
/>}
</div>
</div>
);
}
Buttonbar.propTypes = {
onReadSetup: PropTypes.func.isRequired,
onResetDefaults: PropTypes.func.isRequired,
onWriteSetup: PropTypes.func.isRequired,
};
export default Buttonbar;