From 1b9fa3ea19a05796172bc9902b7327678e0281be Mon Sep 17 00:00:00 2001 From: Michael Winsauer Date: Fri, 18 Jan 2019 22:38:26 +0100 Subject: [PATCH] Added first version of 'remove term' --- service-website/src/SearchTerm.js | 12 +++++++++--- service-website/src/SentimentAnalysis.js | 17 ++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/service-website/src/SearchTerm.js b/service-website/src/SearchTerm.js index 2345071..827268a 100644 --- a/service-website/src/SearchTerm.js +++ b/service-website/src/SearchTerm.js @@ -13,7 +13,11 @@ class SearchTerm extends Component { } handleChange(event) { - console.log(event); + const target = event.target; + const value = target.value; + this.setState({ + value, + }); } handleAddTerm(event) { @@ -21,14 +25,15 @@ class SearchTerm extends Component { } handleRemoveTerm(event) { - + const index = this.props.index; + this.props.onRemoveTerm(index); } render() { return (
- +
); } @@ -37,6 +42,7 @@ class SearchTerm extends Component { SearchTerm.propTypes = { index: PropTypes.number.isRequired, onAddTerm: PropTypes.func.isRequired, + onRemoveTerm: PropTypes.func.isRequired, }; export default SearchTerm; diff --git a/service-website/src/SentimentAnalysis.js b/service-website/src/SentimentAnalysis.js index d32a238..74c4ea6 100644 --- a/service-website/src/SentimentAnalysis.js +++ b/service-website/src/SentimentAnalysis.js @@ -10,6 +10,7 @@ class SentimentAnalysis extends Component { }; this.handleSubmit = this.handleSubmit.bind(this); this.handleAddTerm = this.handleAddTerm.bind(this); + this.handleRemoveTerm = this.handleRemoveTerm.bind(this); this.addEmptyTerm = this.addEmptyTerm.bind(this); this.createEmptyTerm = this.createEmptyTerm.bind(this); } @@ -23,15 +24,25 @@ class SentimentAnalysis extends Component { handleSubmit(event) { event.preventDefault(); + const target = event.target; + console.log(target); const terms = this.state.terms; - console.log(terms); + terms.forEach((term) => { + console.log(term); + }); } handleAddTerm(event) { - console.log(event); this.addEmptyTerm(); } + handleRemoveTerm(index) { + const terms = this.state.terms; + this.setState({ + terms: [...terms.slice(0, index), ...terms.slice(index + 1)], + }); + } + addEmptyTerm() { const term = this.createEmptyTerm(); this.setState({ @@ -42,7 +53,7 @@ class SentimentAnalysis extends Component { createEmptyTerm() { const index = this.state.terms.length; return ( - + ); } -- 2.43.0