Skip to content

Commit eeecbb5

Browse files
authored
Merge pull request #2 from Rhymond/responsiveFixes
Pretify code
2 parents 30f3f97 + 9f6d256 commit eeecbb5

File tree

11 files changed

+66
-67
lines changed

11 files changed

+66
-67
lines changed

src/actions/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/actions/product.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import * as types from '../constants/types';
1+
import * as types from '../constants/types'
22

3-
export function getProducts() {
4-
return dispatch => {
3+
export const getProducts = () =>
4+
dispatch =>
55
fetch(`products.json`)
66
.then(response => response.json())
77
.then(response => {
88
dispatch({
99
type: types.FETCH_PRODUCTS,
1010
payload: response.products
11-
});
11+
})
1212
})
13-
}
14-
}
1513

16-
export function compare(product) {
17-
return {type: types.COMPARE_PRODUCT, product};
18-
}
14+
export const compare = product => ({
15+
type: types.COMPARE_PRODUCT,
16+
product
17+
})

src/components/Compare/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ const Compare = ({products}) =>
4343
</tbody>
4444
</table>
4545
</div>
46-
</div>;
46+
</div>
4747

48-
export default Compare;
48+
export default Compare

src/components/Product/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ const Product = ({product, compare}) =>
1717
</div>
1818
</div>
1919
</div>
20-
</div>;
20+
</div>
2121

22-
export default Product;
22+
export default Product
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import {Product} from '../';
2+
import {Product} from '../'
33

44
const ProductList = ({products, compare}) =>
55
<div>
@@ -8,6 +8,6 @@ const ProductList = ({products, compare}) =>
88
<Product key={product.id} product={product} compare={compare} />
99
)}
1010
</div>
11-
</div>;
11+
</div>
1212

13-
export default ProductList;
13+
export default ProductList

src/constants/types.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export const FETCH_PRODUCTS = 'FETCH_PRODUCTS';
2-
export const COMPARE_PRODUCT = 'COMPARE_PRODUCT';
1+
export const FETCH_PRODUCTS = 'FETCH_PRODUCTS'
2+
export const COMPARE_PRODUCT = 'COMPARE_PRODUCT'

src/containers/App/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import React, {Component} from 'react';
1+
import React, {Component} from 'react'
22
import {Route, Switch} from 'react-router-dom'
33

4-
import {Home, NotFound} from '../';
4+
import {Home, NotFound} from '../'
55

6-
export default class App extends Component {
6+
class App extends Component {
77
render() {
88
return (
9-
<div className="App">
9+
<div className="app">
1010
<div className="container mt-4">
1111
<Switch>
1212
<Route exact path="/" component={Home}/>
1313
<Route component={NotFound}/>
1414
</Switch>
1515
</div>
1616
</div>
17-
);
17+
)
1818
}
1919
}
20+
21+
export default App

src/containers/Home/index.js

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
1-
import React from 'react';
2-
import {bindActionCreators} from 'redux';
3-
import {Compare, ProductList} from '../../components';
4-
import * as productActions from '../../actions';
5-
import {connect} from 'react-redux';
1+
import React, {Component} from 'react'
2+
import {bindActionCreators} from 'redux'
3+
import {Compare, ProductList} from '../../components'
4+
import * as productActions from '../../actions/product'
5+
import {connect} from 'react-redux'
66

7-
class Home extends React.Component {
7+
class Home extends Component {
88
componentWillMount() {
9-
this.props.actions.getProducts();
9+
this.props.actions.getProducts()
1010
}
1111

1212
render() {
13-
const {products, actions} = this.props;
14-
const compareProducts = products.filter(product => product.compare);
13+
const {products, actions} = this.props
14+
const compareProducts = products.filter(product => product.compare)
1515

1616
return (
17-
<div className="Home mt-5">
17+
<div className="home mt-5">
1818
<ProductList products={products} compare={actions.compare}/>
19-
{compareProducts.length >= 2 ? <Compare products={compareProducts}/> : null}
19+
{compareProducts.length >= 2 &&
20+
<Compare products={compareProducts}/>
21+
}
2022
</div>
21-
);
23+
)
2224
}
2325
}
2426

25-
function mapStateToProps(state) {
26-
return {
27+
export default connect(
28+
state => ({
2729
products: state.product.products
28-
}
29-
}
30-
31-
function mapDispatchToProps(dispatch) {
32-
return {
30+
}),
31+
dispatch => ({
3332
actions: bindActionCreators(productActions, dispatch)
34-
};
35-
}
36-
37-
export default connect(
38-
mapStateToProps,
39-
mapDispatchToProps
40-
)(Home);
33+
})
34+
)(Home)

src/containers/NotFound/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import React from 'react'
1+
import React, {Component} from 'react'
22

3-
export default class NotFound extends React.Component {
3+
class NotFound extends Component {
44
render() {
55
return (
6-
<div>
6+
<div className="not-found">
77
<h1>404</h1>
88
<h3>Page not found</h3>
99
</div>
10-
);
10+
)
1111
}
1212
}
13+
14+
export default NotFound

src/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import registerServiceWorker from './registerServiceWorker';
2-
import React from 'react';
3-
import ReactDOM from 'react-dom';
1+
import registerServiceWorker from './registerServiceWorker'
2+
import React from 'react'
3+
import ReactDOM from 'react-dom'
44
import {BrowserRouter} from 'react-router-dom'
55
import {createStore, applyMiddleware} from 'redux'
66
import {Provider} from 'react-redux'
@@ -17,8 +17,8 @@ const loggerMiddleware = createLogger()
1717
const store = createStore(
1818
reducer,
1919
applyMiddleware(
20-
thunkMiddleware, // lets us dispatch() functions
21-
loggerMiddleware // neat middleware that logs actions
20+
thunkMiddleware,
21+
loggerMiddleware
2222
)
2323
)
2424

@@ -27,5 +27,8 @@ ReactDOM.render(
2727
<BrowserRouter>
2828
<App />
2929
</BrowserRouter>
30-
</Provider>, document.getElementById('root'));
31-
registerServiceWorker();
30+
</Provider>,
31+
document.getElementById('root')
32+
)
33+
34+
registerServiceWorker()

0 commit comments

Comments
 (0)