Skip to content

Commit f6d7edc

Browse files
author
jbarroso
committed
Removing containers + adding redux storybook addon
1 parent 044770f commit f6d7edc

18 files changed

Lines changed: 349 additions & 193 deletions

.storybook/addons.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import addons from '@storybook/addons';
2+
import registerRedux from 'addon-redux/register';
3+
registerRedux(addons);

.storybook/decorators.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import { Provider } from 'react-redux';
3+
import addons from '@storybook/addons';
4+
import withReduxCore from 'addon-redux/withRedux';
5+
import store from './store';
6+
7+
export const withRedux = (state, actions) => withReduxCore(addons)({
8+
Provider, store, state, actions
9+
})

.storybook/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ module.exports = {
44
'@storybook/preset-create-react-app',
55
'@storybook/addon-actions',
66
'@storybook/addon-links',
7+
'addon-redux/register',
78
],
89
};
9-

.storybook/store.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createStore } from 'redux';
2+
import withReduxEnhancer from 'addon-redux/enhancer'
3+
import initialState from '../src/reducers/initialState';
4+
5+
export default createStore((state = initialState, _) => state, withReduxEnhancer);

package-lock.json

Lines changed: 176 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"@storybook/addons": "^5.3.19",
8282
"@storybook/preset-create-react-app": "^3.1.1",
8383
"@storybook/react": "^5.3.19",
84+
"addon-redux": "^1.1.0",
8485
"eslint": "^6.8.0",
8586
"eslint-config-airbnb": "^18.1.0",
8687
"eslint-config-prettier": "^6.11.0",

src/components/App.jsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
import React, { useEffect } from 'react';
22
import PropTypes from 'prop-types';
3+
import { useSelector, useDispatch } from 'react-redux';
34

45
import 'todomvc-app-css/index.css';
56

6-
import Header from '../containers/Header';
7-
import MainSection from '../containers/MainSection';
8-
import Footer from '../containers/Footer';
7+
import Header from './Header';
8+
import MainSection from './MainSection';
9+
import Footer from './Footer';
10+
11+
import {
12+
getCompletedTodoCount,
13+
getActiveTodoCount,
14+
getTodosCount,
15+
} from '../selectors';
16+
import { fetchTodos } from '../actions';
917

1018
import * as types from '../constants/TodoFilters';
1119

12-
const App = ({
13-
fetchTodos,
14-
todosCount,
15-
activeTodoCount,
16-
completedCount,
17-
nowShowing,
18-
}) => {
20+
const App = ({ nowShowing }) => {
21+
const todosCount = useSelector(getTodosCount);
22+
const activeTodoCount = useSelector(getActiveTodoCount);
23+
const completedCount = useSelector(getCompletedTodoCount);
24+
25+
const dispatch = useDispatch();
26+
1927
useEffect(() => {
20-
fetchTodos();
21-
}, [fetchTodos]);
28+
dispatch(fetchTodos());
29+
}, [dispatch]);
2230

2331
return (
2432
<section className="todoapp">
@@ -36,15 +44,11 @@ App.defaultProps = {
3644
};
3745

3846
App.propTypes = {
39-
fetchTodos: PropTypes.func.isRequired,
4047
nowShowing: PropTypes.oneOf([
4148
types.ALL_TODOS,
4249
types.ACTIVE_TODOS,
4350
types.COMPLETED_TODOS,
4451
]),
45-
todosCount: PropTypes.number.isRequired,
46-
activeTodoCount: PropTypes.number.isRequired,
47-
completedCount: PropTypes.number.isRequired,
4852
};
4953

5054
export default App;

0 commit comments

Comments
 (0)