hook SoundChangeSuite onChange events to dispatch SET_EPOCH

This commit is contained in:
Sorrel Bri 2019-12-20 13:33:43 -08:00
parent 252529feda
commit 26d85eec4c
2 changed files with 14 additions and 5 deletions

View file

@ -25,11 +25,14 @@ const Epochs = props => {
} }
const updateEpoch = (epoch, epochIndex) => { const updateEpoch = (epoch, epochIndex) => {
let updatedEpochs = [...props.epochs] const dispatchValue = {
updatedEpochs[epochIndex] = epoch name: epoch.name,
index: epochIndex,
changes: epoch.changes
}
props.dispatch({ props.dispatch({
type: "SET_EPOCH", type: "SET_EPOCH",
value: epoch value: dispatchValue
}) })
} }

View file

@ -1,4 +1,4 @@
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import './SoundChangeSuite.scss'; import './SoundChangeSuite.scss';
const SoundChangeSuite = props => { const SoundChangeSuite = props => {
@ -9,6 +9,10 @@ const SoundChangeSuite = props => {
props.updateEpoch(epoch, props.epochIndex); props.updateEpoch(epoch, props.epochIndex);
} }
useEffect(() => {
props.updateEpoch(epoch, props.epochIndex);
}, [epoch])
return ( return (
<div className="SoundChangeSuite" data-testid={`${epoch.name}_SoundChangeSuite`}> <div className="SoundChangeSuite" data-testid={`${epoch.name}_SoundChangeSuite`}>
<h4>{epoch.name}</h4> <h4>{epoch.name}</h4>
@ -19,7 +23,9 @@ const SoundChangeSuite = props => {
id="" cols="30" rows="1" id="" cols="30" rows="1"
value={epoch.name} value={epoch.name}
onChange={e=>changeHandler( onChange={e=>changeHandler(
e, () => setEpoch({...epoch, name:e.target.value}) e, () => {
setEpoch({...epoch, name:e.target.value})
}
)} )}
></textarea> ></textarea>