1 import React, {Component} from "react";
2 import SearchTermsInput from "./SearchTermsInput";
3 import SearchTerm from "./SearchTerm";
5 class SentimentAnalysis extends Component {
6 constructor(props, context) {
11 this.handleSubmit = this.handleSubmit.bind(this);
12 this.handleAddTerm = this.handleAddTerm.bind(this);
13 this.handleRemoveTerm = this.handleRemoveTerm.bind(this);
14 this.addEmptyTerm = this.addEmptyTerm.bind(this);
15 this.createEmptyTerm = this.createEmptyTerm.bind(this);
19 const terms = this.state.terms;
20 if (terms.length === 0) {
26 event.preventDefault();
27 const target = event.target;
29 const terms = this.state.terms;
30 terms.forEach((term) => {
35 handleAddTerm(event) {
39 handleRemoveTerm(index) {
40 const terms = this.state.terms;
42 terms: [...terms.slice(0, index), ...terms.slice(index + 1)],
47 const term = this.createEmptyTerm();
49 terms: [...this.state.terms, term],
54 const index = this.state.terms.length;
56 <SearchTerm key={index} index={index} onAddTerm={this.handleAddTerm} onRemoveTerm={this.handleRemoveTerm}/>
62 <div className="sentiment-analysis">
63 <form onSubmit={this.handleSubmit}>
64 <label>Search Terms</label>
65 <SearchTermsInput terms={this.state.terms} onAddTerm={this.handleAddTerm}/>
66 <input type="submit" value="Submit"/>
73 SentimentAnalysis.propTypes = {};
75 export default SentimentAnalysis;