Added dropdown box component for parts of speech, but editing words isn't working for some reason on Linux.

This commit is contained in:
Robbie Antenesse 2016-11-28 09:32:20 -07:00
parent 16193c1bf4
commit 7829b484c2
5 changed files with 21 additions and 7 deletions

View File

@ -20,6 +20,7 @@ export class Dictionary extends React.Component {
simpleDefinition={word.simpleDefinition} simpleDefinition={word.simpleDefinition}
longDefinition={word.longDefinition} longDefinition={word.longDefinition}
wordId={word.wordId} wordId={word.wordId}
dictionary={this}
updateWord={(wordId, wordObject) => this.props.updateWord(wordId, wordObject)} /> updateWord={(wordId, wordObject) => this.props.updateWord(wordId, wordObject)} />
); );
}); });

View File

@ -1,12 +1,14 @@
import React from 'react'; import React from 'react';
import {Input} from './Input'; import {Input} from './Input';
import {htmlEntities} from '../js/helpers';
export class Dropdown extends Input { export class Dropdown extends Input {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
value: props.value || false value: props.value || ' '
, isDisabled: props.isDisabled || false , isDisabled: props.isDisabled || false
}; };
} }
@ -14,7 +16,7 @@ export class Dropdown extends Input {
// Whenever the input changes, update the value state of this component // Whenever the input changes, update the value state of this component
handleOnChange(event) { handleOnChange(event) {
this.setState({ this.setState({
value: event.target.checked value: event.currentTarget.value
}); });
} }
@ -22,9 +24,11 @@ export class Dropdown extends Input {
let results = []; let results = [];
let options = optionsString.split(','); let options = optionsString.split(',');
options.forEach((option) => { options.forEach((option, index) => {
let optionValue = htmlEntities(option.trim());
results.push( results.push(
<option> <option key={`o:${index}v:${optionValue}`} value={optionValue}>
{option.trim()} {option.trim()}
</option> </option>
); );
@ -40,7 +44,8 @@ export class Dropdown extends Input {
{this.props.name} {this.props.name}
{this.showHelperLink()} {this.showHelperLink()}
</span> </span>
<select onChange={this.handleOnChange} disabled={(this.state.isDisabled) ? 'disabled' : null}> <select value={this.state.value} onChange={this.handleOnChange} disabled={(this.state.isDisabled) ? 'disabled' : null}>
<option value=" "></option>
{this.parseOptions(this.props.optionsList)} {this.parseOptions(this.props.optionsList)}
</select> </select>
</label> </label>

View File

@ -82,6 +82,7 @@ export class Word extends React.Component {
if (this.state.editWord) { if (this.state.editWord) {
return ( return (
<WordForm <WordForm
partsOfSpeech={this.props.dictionary.props.settings.partsOfSpeech}
updateWord={(wordObject) => this.updateWord(wordObject)} updateWord={(wordObject) => this.updateWord(wordObject)}
wordValues={this.packageThisWordIntoObject()} wordValues={this.packageThisWordIntoObject()}
submitLabel='Update' /> submitLabel='Update' />

View File

@ -3,6 +3,7 @@ import React from 'react';
import {keyCodeFor} from '../js/helpers' import {keyCodeFor} from '../js/helpers'
import {Input} from './Input'; import {Input} from './Input';
import {Dropdown} from './Dropdown';
import {TextArea} from './TextArea'; import {TextArea} from './TextArea';
import {Button} from './Button'; import {Button} from './Button';
@ -107,7 +108,8 @@ export class WordForm extends React.Component {
onKeyDown={(event) => this.submitWordOnCtrlEnter(event)} onKeyDown={(event) => this.submitWordOnCtrlEnter(event)}
ref={(inputComponent) => this.pronunciationField = inputComponent} /> ref={(inputComponent) => this.pronunciationField = inputComponent} />
<Input name='Part of Speech' <Dropdown name='Part of Speech'
optionsList={this.props.partsOfSpeech}
value={partOfSpeechDefaultValue} value={partOfSpeechDefaultValue}
ref={(inputComponent) => this.partOfSpeechField = inputComponent} /> ref={(inputComponent) => this.partOfSpeechField = inputComponent} />

View File

@ -132,6 +132,8 @@ class Lexiconga extends React.Component {
// Search the words list for the first word with the given idea and return its index in the array. // Search the words list for the first word with the given idea and return its index in the array.
firstIndexWordWithId(id) { firstIndexWordWithId(id) {
this.state.words.forEach((word, index) => { this.state.words.forEach((word, index) => {
console.log('given id: ' + typeof id + ' ' + id + '\n' + typeof word.wordId + ' ' + word.wordId + ' ' + word.name);
if (word.wordId === id) { if (word.wordId === id) {
return index; return index;
} }
@ -247,7 +249,10 @@ class Lexiconga extends React.Component {
<div className='left-column'> <div className='left-column'>
<div className='floating-form'> <div className='floating-form'>
<WordForm addWord={(wordObject) => this.addWord(wordObject)} submitLabel='Add Word' /> <WordForm
partsOfSpeech={this.state.settings.partsOfSpeech}
addWord={(wordObject) => this.addWord(wordObject)}
submitLabel='Add Word' />
</div> </div>
</div> </div>