handleURLSubmit()

in frontend/src/App.js [71:100]


  handleURLSubmit(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.url);
    if (this.state.url === undefined || this.state.url === "") {
      console.log("Empty URL field");
      this.setState({pictures: [], completed:0});
    } else {
      const myInit = {
        body: {"url": this.state.url, "k": this.state.k}
      };
      this.setState({completed:66});
      API.post('ImageSearch', '/postURL', myInit)
      .then(response => {
        this.setState({pictures: response.images.map(function(elem) {
          let picture = {};
          picture.img = elem;
          picture.cols = 1;
          return picture;
        })
      }); 
      this.setState({completed:100});
      console.log(this.state.pictures);
      })
      .catch(error => {
        console.log(error);
      });
    };
    event.preventDefault();
  }