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) => {
let updatedEpochs = [...props.epochs]
updatedEpochs[epochIndex] = epoch
const dispatchValue = {
name: epoch.name,
index: epochIndex,
changes: epoch.changes
}
props.dispatch({
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';
const SoundChangeSuite = props => {
@ -8,6 +8,10 @@ const SoundChangeSuite = props => {
cb(e);
props.updateEpoch(epoch, props.epochIndex);
}
useEffect(() => {
props.updateEpoch(epoch, props.epochIndex);
}, [epoch])
return (
<div className="SoundChangeSuite" data-testid={`${epoch.name}_SoundChangeSuite`}>
@ -19,7 +23,9 @@ const SoundChangeSuite = props => {
id="" cols="30" rows="1"
value={epoch.name}
onChange={e=>changeHandler(
e, () => setEpoch({...epoch, name:e.target.value})
e, () => {
setEpoch({...epoch, name:e.target.value})
}
)}
></textarea>