refactor Epoch component
This commit is contained in:
parent
c13cc33697
commit
74bbca028f
1 changed files with 28 additions and 24 deletions
|
@ -7,23 +7,25 @@ import { render } from 'react-dom';
|
|||
|
||||
|
||||
const Epochs = ({epochs, errors, dispatch}) => {
|
||||
const handleEvent = func => e => {
|
||||
e.preventDefault();
|
||||
return func;
|
||||
}
|
||||
|
||||
const addEpoch = e => {
|
||||
e.preventDefault()
|
||||
const addEpoch = e => handleEvent(() => {
|
||||
let index = epochs.length + 1;
|
||||
dispatch({
|
||||
type: 'ADD_EPOCH',
|
||||
value: {name: `Epoch ${index}`}
|
||||
value: {name: `epoch ${index}`}
|
||||
})
|
||||
}
|
||||
})(e)
|
||||
|
||||
const removeEpoch = (e, epochName) => {
|
||||
e.preventDefault()
|
||||
const removeEpoch = e => handleEvent(
|
||||
dispatch({
|
||||
type: 'REMOVE_EPOCH',
|
||||
value: {name: epochName}
|
||||
});
|
||||
}
|
||||
})
|
||||
)(e);
|
||||
|
||||
const updateEpoch = (epoch, epochIndex) => {
|
||||
const dispatchValue = {
|
||||
|
@ -48,7 +50,8 @@ const Epochs = ({epochs, errors, dispatch}) => {
|
|||
}
|
||||
|
||||
const renderEpochs = () => {
|
||||
if (epochs && epochs.length) return epochs.map((epoch, index) => {
|
||||
if (epochs && epochs.length) {
|
||||
return epochs.map((epoch, index) => {
|
||||
const epochError = errors.epoch ? errors.error : null
|
||||
return (
|
||||
<div
|
||||
|
@ -65,6 +68,7 @@ const Epochs = ({epochs, errors, dispatch}) => {
|
|||
{renderAddEpochButton(index)}
|
||||
</div>
|
||||
)});
|
||||
}
|
||||
return renderAddEpochButton(-1)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue