From 74bbca028fa9b6f257aad537f99000e01cf3e836 Mon Sep 17 00:00:00 2001 From: Sorrel Bri Date: Sun, 1 Mar 2020 15:41:25 -0800 Subject: [PATCH] refactor Epoch component --- src/components/Epochs.js | 52 +++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/components/Epochs.js b/src/components/Epochs.js index 3764d10..820a1d4 100644 --- a/src/components/Epochs.js +++ b/src/components/Epochs.js @@ -7,23 +7,25 @@ import { render } from 'react-dom'; const Epochs = ({epochs, errors, dispatch}) => { - - const addEpoch = e => { - e.preventDefault() + const handleEvent = func => e => { + e.preventDefault(); + return func; + } + + 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,23 +50,25 @@ 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 ( -
- - {renderAddEpochButton(index)} -
- )}); +
+ + {renderAddEpochButton(index)} +
+ )}); + } return renderAddEpochButton(-1) }