in frontend/src/App.js [79:132]
handleSearchSubmit(event) {
// function for when a use submits a URL
// if the URL bar is empty, it will remove similar photos from state
console.log(this.state.searchText);
if (this.state.searchText === undefined || this.state.searchText === "") {
console.log("Empty Text field");
this.setState({pictures: [], completed: 0, results: []});
} else {
const myInit = {
body: {"searchString": this.state.searchText, "k": this.state.k}
};
this.setState({completed:66});
API.post('NluSearch', '/postText', myInit)
.then(response => {
this.setState({pictures: response.images.map(function(elem) {
let picture = {};
picture.img = elem;
picture.cols = 1;
return picture;
})
});
console.log(this.state.pictures);
})
.catch(error => {
console.log(error);
});
this.setState({completed:85});
console.log(this.state.results);
API.post('NluSearch', '/postMatch', myInit)
.then(response => {
// this.setState({results: []});
this.setState({results: response.map(function(elem) {
let result = {};
result.img = elem.presigned_url;
result.cols = 1;
result.description = elem.description;
return result;
})
});
console.log(this.state.results);
this.setState({completed:100});
})
.catch(error => {
console.log(error);
});
};
event.preventDefault();
}