diff --git a/src/3-refactorable/good/actions/index.js b/src/3-refactorable/good/actions/index.js
index 5337b16..d268be5 100644
--- a/src/3-refactorable/good/actions/index.js
+++ b/src/3-refactorable/good/actions/index.js
@@ -1,8 +1,6 @@
import * as types from '../constants/ActionTypes';
-export const addToCart = productId => (dispatch, getState) => {
- dispatch({
- type: types.ADD_TO_CART,
- productId,
- });
-};
+export const addToCart = productId => ({
+ type: types.ADD_TO_CART,
+ productId,
+});
diff --git a/src/3-refactorable/good/components/Cart.js b/src/3-refactorable/good/components/Cart.js
index 4c35be8..7cc4d37 100644
--- a/src/3-refactorable/good/components/Cart.js
+++ b/src/3-refactorable/good/components/Cart.js
@@ -4,9 +4,20 @@ export default class Cart extends Component {
constructor(props) {
super();
+ this.state = {
+ cart: props.cart,
+ inventory: props.inventory,
+ localCurrency: props.localCurrency,
+ };
+
this.CurrencyConverter = props.currencyConverter;
}
+ componentWillReceiveProps(nextProps) {
+ this.setState({
+ cart: nextProps.cart,
+ });
+ }
render() {
return (
diff --git a/src/3-refactorable/good/components/Inventory.js b/src/3-refactorable/good/components/Inventory.js
index 6c884d2..5805d41 100644
--- a/src/3-refactorable/good/components/Inventory.js
+++ b/src/3-refactorable/good/components/Inventory.js
@@ -14,6 +14,7 @@ export default class Inventory extends Component {
}
onSelectCurrency(e) {
+ window.localCurrency = e.target.value;
this.setState({
localCurrency: e.target.value,
});
@@ -80,7 +81,7 @@ export default class Inventory extends Component {
- |
diff --git a/src/3-refactorable/good/containers/App.js b/src/3-refactorable/good/containers/App.js
index b8e9ed0..dc23a57 100644
--- a/src/3-refactorable/good/containers/App.js
+++ b/src/3-refactorable/good/containers/App.js
@@ -1,15 +1,9 @@
import React, { Component } from 'react';
-import { createStore } from 'redux';
-import { Provider, connect } from 'react-redux';
-import Inventory from '../components/Inventory';
-import Cart from '../components/Cart';
+import Inventory from '../containers/Inventory';
+import Cart from '../containers/Cart';
export default class App extends Component {
- constructor() {
- super();
- }
-
render() {
return (
diff --git a/src/3-refactorable/good/containers/Cart.js b/src/3-refactorable/good/containers/Cart.js
index 3e8dd33..0a60e5b 100644
--- a/src/3-refactorable/good/containers/Cart.js
+++ b/src/3-refactorable/good/containers/Cart.js
@@ -1,16 +1,15 @@
-import React, { PropTypes } from 'react';
+import React from 'react';
import { connect } from 'react-redux';
-import addToCart from '../actions';
import CurrencyConverter from '../lib/CurrencyConverter';
import Cart from '../components/Cart';
-const CartContainer = ({ cart, addToCart }) => (
+const CartContainer = ({ cart }) => (
addToCart(productId)}
/>
);
@@ -18,4 +17,4 @@ const mapStateToProps = state => ({
cart: state.cart,
});
-export default connect(mapStateToProps, { addToCart })(CartContainer);
+export default connect(mapStateToProps, {})(CartContainer);
diff --git a/src/3-refactorable/good/containers/Inventory.js b/src/3-refactorable/good/containers/Inventory.js
index 5db7428..4dec9ef 100644
--- a/src/3-refactorable/good/containers/Inventory.js
+++ b/src/3-refactorable/good/containers/Inventory.js
@@ -1,6 +1,6 @@
-import React, { PropTypes } from 'react';
+import React from 'react';
import { connect } from 'react-redux';
-import addToCart from '../actions';
+import { addToCart } from '../actions';
import CurrencyConverter from '../lib/CurrencyConverter';
import Inventory from '../components/Inventory';
diff --git a/src/3-refactorable/good/reducers/cart.js b/src/3-refactorable/good/reducers/cart.js
index 84c171f..e55674a 100644
--- a/src/3-refactorable/good/reducers/cart.js
+++ b/src/3-refactorable/good/reducers/cart.js
@@ -1,13 +1,11 @@
import { ADD_TO_CART } from '../constants/ActionTypes';
-const initialState = {
- productIds: [],
-};
+const initialState = [];
export default (state = initialState, action) => {
switch (action.type) {
case 'ADD_TO_CART':
- return [...state, action.productId];
+ return [...state, parseInt(action.productId)];
default:
return state;
}