Got word editing working correctly. Need to add labels to fields, maybe use word form component instead.

Need to fix simpleDefinition not updating.
This commit is contained in:
Robbie Antenesse 2016-09-23 11:59:38 -06:00
parent 821330073a
commit 6e13c7da53
1 changed files with 22 additions and 83 deletions

View File

@ -34,55 +34,26 @@ export class Word extends React.Component {
showName() { showName() {
let editButton; let editButton;
if (this.state.editName) { if (this.state.editWord) {
if (this.state.editWord) {
editButton = (
<Button
action={() => {
let value = this.nameField.state.value;
this.setState({editName: false}, () => {
this.updateWord({name: value});
});
}}
label={saveIcon} />
);
}
return ( return (
<div> <div>
<Input value={this.props.name} ref={(inputComponent) => this.nameField = inputComponent} /> <Input value={this.props.name} ref={(inputComponent) => this.nameField = inputComponent} />
{editButton}
</div> </div>
); );
} else { } else {
if (this.state.editWord) {
<Button
action={() => {
this.setState({editName: true});
}}
label={editIcon} />
}
return ( return (
<div className='name'> <div className='name'>
{this.props.name} {this.props.name}
{editButton}
</div> </div>
); );
} }
} }
showPronunciation() { showPronunciation() {
if (this.state.editPronunciation) { if (this.state.editWord) {
return ( return (
<div> <div>
<Input value={this.props.pronunciation} ref={(inputComponent) => this.pronunciationField = inputComponent} /> <Input value={this.props.pronunciation} ref={(inputComponent) => this.pronunciationField = inputComponent} />
<Button
action={() => {
let value = this.pronunciationField.state.value;
this.setState({editPronunciation: false}, () => {
this.updateWord({pronunciation: value});
});
}}
label={saveIcon} />
</div> </div>
); );
} else { } else {
@ -90,11 +61,6 @@ export class Word extends React.Component {
return ( return (
<div className='pronunciation'> <div className='pronunciation'>
{this.props.pronunciation} {this.props.pronunciation}
<Button
action={() => {
this.setState({editPronunciation: true});
}}
label={editIcon} />
</div> </div>
); );
} }
@ -102,18 +68,10 @@ export class Word extends React.Component {
} }
showPartOfSpeech() { showPartOfSpeech() {
if (this.state.editPartOfSpeech) { if (this.state.editWord) {
return ( return (
<div> <div>
<Input value={this.props.partOfSpeech} ref={(inputComponent) => this.partOfSpeechField = inputComponent} /> <Input value={this.props.partOfSpeech} ref={(inputComponent) => this.partOfSpeechField = inputComponent} />
<Button
action={() => {
let value = this.partOfSpeechField.state.value;
this.setState({editPartOfSpeech: false}, () => {
this.updateWord({partOfSpeech: value});
});
}}
label={saveIcon} />
</div> </div>
); );
} else { } else {
@ -121,11 +79,6 @@ export class Word extends React.Component {
return ( return (
<div className='part-of-speech'> <div className='part-of-speech'>
{this.props.partOfSpeech} {this.props.partOfSpeech}
<Button
action={() => {
this.setState({editPartOfSpeech: true});
}}
label={editIcon} />
</div> </div>
); );
} }
@ -133,18 +86,10 @@ export class Word extends React.Component {
} }
showSimpleDefinition() { showSimpleDefinition() {
if (this.state.editSimpleDefinition) { if (this.state.editWord) {
return ( return (
<div> <div>
<Input value={this.props.simpleDefinition} ref={(inputComponent) => this.simpleDefinitionField = inputComponent} /> <Input value={this.props.simpleDefinition} ref={(inputComponent) => this.simpleDefinitionField = inputComponent} />
<Button
action={() => {
let value = this.simpleDefinitionField.state.value;
this.setState({editSimpleDefinition: false}, () => {
this.updateWord({simpleDefinition: value});
});
}}
label={saveIcon} />
</div> </div>
); );
} else { } else {
@ -152,11 +97,6 @@ export class Word extends React.Component {
return ( return (
<div className='simple-definition'> <div className='simple-definition'>
{this.props.simpleDefinition} {this.props.simpleDefinition}
<Button
action={() => {
this.setState({editSimpleDefinition: true});
}}
label={editIcon} />
</div> </div>
); );
} }
@ -164,18 +104,10 @@ export class Word extends React.Component {
} }
showLongDefinition() { showLongDefinition() {
if (this.state.editLongDefinition) { if (this.state.editWord) {
return ( return (
<div> <div>
<Input value={this.props.longDefinition} ref={(inputComponent) => this.longDefinitionField = inputComponent} /> <Input value={this.props.longDefinition} ref={(inputComponent) => this.longDefinitionField = inputComponent} />
<Button
action={() => {
let value = this.longDefinitionField.state.value;
this.setState({editLongDefinition: false}, () => {
this.updateWord({longDefinition: value});
});
}}
label={saveIcon} />
</div> </div>
); );
} else { } else {
@ -183,11 +115,6 @@ export class Word extends React.Component {
return ( return (
<div className='long-definition'> <div className='long-definition'>
{this.props.longDefinition} {this.props.longDefinition}
<Button
action={() => {
this.setState({editLongDefinition: true});
}}
label={editIcon} />
</div> </div>
); );
} }
@ -198,11 +125,23 @@ export class Word extends React.Component {
if (this.props.isEditing) { if (this.props.isEditing) {
if (this.state.editWord) { if (this.state.editWord) {
return ( return (
<Button <div>
action={() => { <Button
this.setState({editWord: false}); action={() => {
}} let values = {
label='Stop Editing' /> name: this.nameField.state.value,
pronunciation: this.pronunciationField.state.value,
partOfSpeech: this.partOfSpeechField.state.value,
simpleDefinition: this.simpleDefinitionField.state.value,
longDefinition: this.longDefinitionField.state.value
}
this.setState({editWord: false}, () => this.updateWord(values));
}}
label='Save' />
<Button
action={() => this.setState({editWord: false})}
label='Cancel' />
</div>
); );
} else { } else {
return ( return (