From 531df607c266647636070a25703f6ccfbe834f98 Mon Sep 17 00:00:00 2001 From: Andrew Westenskow Date: Fri, 15 May 2020 11:51:33 -0600 Subject: [PATCH] Removed completed code --- src/App.js | 155 ++++++++++++++++++++++------------------------------- 1 file changed, 65 insertions(+), 90 deletions(-) diff --git a/src/App.js b/src/App.js index 1a1fe9e4b..80fb8007e 100644 --- a/src/App.js +++ b/src/App.js @@ -1,42 +1,36 @@ -import React, { Component } from 'react'; -import logo from './mainStreetAuto.svg'; -import axios from 'axios'; -import './App.css'; +import React, { Component } from 'react' +import logo from './mainStreetAuto.svg' +import axios from 'axios' +import './App.css' // Toast notification dependencies -import { ToastContainer, toast } from 'react-toastify'; +import { ToastContainer, toast } from 'react-toastify' class App extends Component { constructor(props) { - super(props); + super(props) this.state = { vehiclesToDisplay: [], - buyersToDisplay: [] - }; - - this.getVehicles = this.getVehicles.bind(this); - this.getPotentialBuyers = this.getPotentialBuyers.bind(this); - this.sellCar = this.sellCar.bind(this); - this.addCar = this.addCar.bind(this); - this.filterByColor = this.filterByColor.bind(this); - this.filterByMake = this.filterByMake.bind(this); - this.addBuyer = this.addBuyer.bind(this); - this.nameSearch = this.nameSearch.bind(this); - this.resetData = this.resetData.bind(this); - this.byYear = this.byYear.bind(this); - this.deleteBuyer = this.deleteBuyer.bind(this); + buyersToDisplay: [], + } + + this.getVehicles = this.getVehicles.bind(this) + this.getPotentialBuyers = this.getPotentialBuyers.bind(this) + this.sellCar = this.sellCar.bind(this) + this.addCar = this.addCar.bind(this) + this.filterByColor = this.filterByColor.bind(this) + this.filterByMake = this.filterByMake.bind(this) + this.addBuyer = this.addBuyer.bind(this) + this.nameSearch = this.nameSearch.bind(this) + this.resetData = this.resetData.bind(this) + this.byYear = this.byYear.bind(this) + this.deleteBuyer = this.deleteBuyer.bind(this) } getVehicles() { // axios (GET) // setState with response -> vehiclesToDisplay - axios.get('https://joes-autos.herokuapp.com/api/vehicles') - .then(response => { - toast.success('Got all vehicles') - this.setState({vehiclesToDisplay: response.data}) - }) - .catch(() => toast.error('Failed to get vehicles')) } getPotentialBuyers() { @@ -47,23 +41,17 @@ class App extends Component { sellCar(id) { // axios (DELETE) // setState with response -> vehiclesToDisplay - axios.delete(`https://joes-autos.herokuapp.com/api/vehicles/${id}`) - .then(response => { - toast.success('Sold car') - this.setState({vehiclesToDisplay: response.data.vehicles}) - }) - .catch(() => toast.error('Failed to sell car')) } filterByMake() { - let make = this.selectedMake.value; + let make = this.selectedMake.value // axios (GET) // setState with response -> vehiclesToDisplay } filterByColor() { - let color = this.selectedColor.value; + let color = this.selectedColor.value // axios (GET) // setState with response -> vehiclesToDisplay @@ -72,12 +60,6 @@ class App extends Component { updatePrice(priceChange, id) { // axios (PUT) // setState with response -> vehiclesToDisplay - axios.put(`https://joes-autos.herokuapp.com/api/vehicles/${id}/${priceChange}`) - .then(response => { - toast.success('Updated Price') - this.setState({vehiclesToDisplay: response.data.vehicles}) - }) - .catch(() => toast.error('Failed to update price')) } addCar() { @@ -86,25 +68,19 @@ class App extends Component { model: this.model.value, color: this.color.value, year: this.year.value, - price: this.price.value - }; + price: this.price.value, + } // axios (POST) // setState with response -> vehiclesToDisplay - axios.post('https://joes-autos.herokuapp.com/api/vehicles', newCar) - .then(response => { - toast.success('Added car') - this.setState({vehiclesToDisplay: response.data.vehicles}) - }) - .catch(() => toast.error('Failed to add car')) } addBuyer() { let newBuyer = { name: this.name.value, phone: this.phone.value, - address: this.address.value - }; + address: this.address.value, + } //axios (POST) // setState with response -> buyersToDisplay @@ -116,14 +92,13 @@ class App extends Component { } nameSearch() { - let searchLetters = this.searchLetters.value; - + let searchLetters = this.searchLetters.value // axios (GET) // setState with response -> buyersToDisplay } byYear() { - let year = this.searchYear.value; + let year = this.searchYear.value // axios (GET) // setState with response -> vehiclesToDisplay @@ -133,18 +108,18 @@ class App extends Component { resetData(dataToReset) { axios .get('https://joes-autos.herokuapp.com/api/' + dataToReset + '/reset') - .then(res => { + .then((res) => { if (dataToReset === 'vehicles') { - this.setState({ vehiclesToDisplay: res.data.vehicles }); + this.setState({ vehiclesToDisplay: res.data.vehicles }) } else { - this.setState({ buyersToDisplay: res.data.buyers }); + this.setState({ buyersToDisplay: res.data.buyers }) } - }); + }) } // Do not edit the code above render() { - const vehicles = this.state.vehiclesToDisplay.map(v => { + const vehicles = this.state.vehiclesToDisplay.map((v) => { return (

Make: {v.make}

@@ -173,10 +148,10 @@ class App extends Component {
- ); - }); + ) + }) - const buyers = this.state.buyersToDisplay.map(person => { + const buyers = this.state.buyersToDisplay.map((person) => { return (

Name: {person.name}

@@ -186,7 +161,7 @@ class App extends Component {
- ); - }); + ) + }) return (
@@ -226,8 +201,8 @@ class App extends Component { { - this.searchYear = searchYear; + ref={(searchYear) => { + this.searchYear = searchYear }} className="btn-sp" type="number" @@ -298,38 +273,38 @@ class App extends Component { { - this.make = make; + ref={(make) => { + this.make = make }} /> { - this.model = model; + ref={(model) => { + this.model = model }} /> { - this.year = year; + ref={(year) => { + this.year = year }} /> { - this.color = color; + ref={(color) => { + this.color = color }} /> { - this.price = price; + ref={(price) => { + this.price = price }} /> @@ -342,22 +317,22 @@ class App extends Component { { - this.name = name; + ref={(name) => { + this.name = name }} /> { - this.phone = phone; + ref={(phone) => { + this.phone = phone }} /> { - this.address = address; + ref={(address) => { + this.address = address }} /> @@ -380,8 +355,8 @@ class App extends Component {
- ); + ) } } -export default App; +export default App