diff --git a/src/components/App.js b/src/components/App.js index 8ce01f3..37973a3 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -13,13 +13,6 @@ class App extends React.Component { constructor() { super(); - this.addFish = this.addFish.bind(this); - this.loadSamples = this.loadSamples.bind(this); - this.addToOrder = this.addToOrder.bind(this); - this.updateFish = this.updateFish.bind(this); - this.removeFish = this.removeFish.bind(this); - this.removeFromOrder = this.removeFromOrder.bind(this); - this.state = { fishes: {}, order: {} @@ -50,42 +43,42 @@ class App extends React.Component { } - addFish(fish) { + addFish = (fish) => { const fishes = {...this.state.fishes}; const timestamp = Date.now(); fishes[`fish-${timestamp}`] = fish; this.setState({ fishes }) - } + }; - updateFish (key, updatedFish) { + updateFish = (key, updatedFish) => { const fishes = {...this.state.fishes}; fishes[key] = updatedFish; this.setState({ fishes }); - } + }; - removeFish(key) { + removeFish = (key) => { const fishes = {...this.state.fishes}; fishes[key] = null; this.setState({ fishes }); - } + }; - loadSamples() { + loadSamples = () => { this.setState({ fishes: sampleFishes }); - } + }; - addToOrder(key) { + addToOrder = (key) => { const order = {...this.state.order}; order[key] = order[key] + 1 || 1; this.setState({ order }); - } + }; - removeFromOrder(key) { + removeFromOrder = (key) => { const order = {...this.state.order}; delete order[key]; this.setState({ order }); - } + }; render() { return ( diff --git a/src/components/Inventory.js b/src/components/Inventory.js index afa0747..db35935 100644 --- a/src/components/Inventory.js +++ b/src/components/Inventory.js @@ -6,12 +6,7 @@ import base from '../base'; class Inventory extends React.Component { constructor () { super(); - this.renderInventory = this.renderInventory.bind(this); - this.handleChange = this.handleChange.bind(this); - this.renderLogin = this.renderLogin.bind(this); - this.logout = this.logout.bind(this); - this.authenticate = this.authenticate.bind(this); - this.authHandler = this.authHandler.bind(this); + this.state = { uid: null, owner: null @@ -26,31 +21,31 @@ class Inventory extends React.Component { }); } - handleChange(e, key) { + handleChange = (e, key) => { const fish = this.props.fishes[key]; const updatedFish = { ...fish, [e.target.name]: e.target.value } this.props.updateFish(key, updatedFish); - } + }; - authenticate(provider) { + authenticate = (provider) => { console.log(`Trying to log in with ${provider}`); base.authWithOAuthPopup(provider, this.authHandler); - } + }; - logout() { + logout = () => { base.unauth(); this.setState({ uid: null }); - } + }; - authHandler(err, authData) { + authHandler = (err, authData) => { console.log(authData); if(err) { console.error(err); return; - } + }; //grab store info const storeRef = base.database().ref(this.props.storeId); @@ -59,7 +54,6 @@ class Inventory extends React.Component { storeRef.once('value', (snapshot) => { const data = snapshot.val() || {}; - //claim it as our own if there is no owner already if(!data.owner) { storeRef.set({ @@ -74,7 +68,7 @@ class Inventory extends React.Component { }); } - renderLogin() { + renderLogin = () => { return ( ) - } + }; - renderInventory(key) { + renderInventory = (key) => { const fish = this.props.fishes[key]; return (
@@ -102,7 +96,7 @@ class Inventory extends React.Component {
) - } + }; render() { const logout = diff --git a/src/components/NotFound.js b/src/components/NotFound.js index 787cdb3..81c54de 100644 --- a/src/components/NotFound.js +++ b/src/components/NotFound.js @@ -6,5 +6,4 @@ const NotFound = ({location}) => ( ) - export default NotFound; diff --git a/src/components/Order.js b/src/components/Order.js index fe234fa..670475b 100644 --- a/src/components/Order.js +++ b/src/components/Order.js @@ -5,18 +5,15 @@ import PropTypes from 'prop-types'; class Order extends React.Component { - constructor () { - super(); - this.renderOrder = this.renderOrder.bind(this); - } - renderOrder(key) { + + renderOrder = (key) => { const fish = this.props.fishes[key]; const count = this.props.order[key]; const removeButton = if(!fish || fish.status === 'unavailable') { return
  • Sorry, {fish ? fish.name : 'fish'} is no longer available! {removeButton}
  • - } + }; return (