Skip to content

Commit 0a0c8f6

Browse files
authored
Merge pull request gothinkster#51 from foopang/fix/constants
Use constants for action types
2 parents 390c2f1 + 2c9fa98 commit 0a0c8f6

26 files changed

+254
-104
lines changed

src/components/App.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import agent from '../agent';
22
import Header from './Header';
33
import React from 'react';
44
import { connect } from 'react-redux';
5+
import { APP_LOAD, REDIRECT } from '../constants/actionTypes';
56

67
const mapStateToProps = state => ({
78
appLoaded: state.common.appLoaded,
@@ -12,9 +13,9 @@ const mapStateToProps = state => ({
1213

1314
const mapDispatchToProps = dispatch => ({
1415
onLoad: (payload, token) =>
15-
dispatch({ type: 'APP_LOAD', payload, token, skipTracking: true }),
16+
dispatch({ type: APP_LOAD, payload, token, skipTracking: true }),
1617
onRedirect: () =>
17-
dispatch({ type: 'REDIRECT' })
18+
dispatch({ type: REDIRECT })
1819
});
1920

2021
class App extends React.Component {

src/components/Article/ArticleActions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { Link } from 'react-router';
22
import React from 'react';
33
import agent from '../../agent';
44
import { connect } from 'react-redux';
5+
import { DELETE_ARTICLE } from '../../constants/actionTypes';
56

67
const mapDispatchToProps = dispatch => ({
78
onClickDelete: payload =>
8-
dispatch({ type: 'DELETE_ARTICLE', payload })
9+
dispatch({ type: DELETE_ARTICLE, payload })
910
});
1011

1112
const ArticleActions = props => {

src/components/Article/CommentInput.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react';
22
import agent from '../../agent';
33
import { connect } from 'react-redux';
4+
import { ADD_COMMENT } from '../../constants/actionTypes';
45

56
const mapDispatchToProps = dispatch => ({
67
onSubmit: payload =>
7-
dispatch({ type: 'ADD_COMMENT', payload })
8+
dispatch({ type: ADD_COMMENT, payload })
89
});
910

1011
class CommentInput extends React.Component {

src/components/Article/DeleteButton.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react';
22
import agent from '../../agent';
33
import { connect } from 'react-redux';
4+
import { DELETE_COMMENT } from '../../constants/actionTypes';
45

56
const mapDispatchToProps = dispatch => ({
67
onClick: (payload, commentId) =>
7-
dispatch({ type: 'DELETE_COMMENT', payload, commentId })
8+
dispatch({ type: DELETE_COMMENT, payload, commentId })
89
});
910

1011
const DeleteButton = props => {

src/components/Article/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import React from 'react';
77
import agent from '../../agent';
88
import { connect } from 'react-redux';
99
import marked from 'marked';
10+
import { ARTICLE_PAGE_LOADED, ARTICLE_PAGE_UNLOADED } from '../../constants/actionTypes';
1011

1112
const mapStateToProps = state => ({
1213
...state.article,
@@ -15,9 +16,9 @@ const mapStateToProps = state => ({
1516

1617
const mapDispatchToProps = dispatch => ({
1718
onLoad: payload =>
18-
dispatch({ type: 'ARTICLE_PAGE_LOADED', payload }),
19+
dispatch({ type: ARTICLE_PAGE_LOADED, payload }),
1920
onUnload: () =>
20-
dispatch({ type: 'ARTICLE_PAGE_UNLOADED' })
21+
dispatch({ type: ARTICLE_PAGE_UNLOADED })
2122
});
2223

2324
class Article extends React.Component {

src/components/ArticlePreview.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import React from 'react';
44
import { Link } from 'react-router';
55
import agent from '../agent';
66
import { connect } from 'react-redux';
7+
import { ARTICLE_FAVORITED, ARTICLE_UNFAVORITED } from '../constants/actionTypes';
78

89
const FAVORITED_CLASS = 'btn btn-sm btn-primary';
910
const NOT_FAVORITED_CLASS = 'btn btn-sm btn-outline-primary';
1011

1112
const mapDispatchToProps = dispatch => ({
1213
favorite: slug => dispatch({
13-
type: 'ARTICLE_FAVORITED',
14+
type: ARTICLE_FAVORITED,
1415
payload: agent.Articles.favorite(slug)
1516
}),
1617
unfavorite: slug => dispatch({
17-
type: 'ARTICLE_UNFAVORITED',
18+
type: ARTICLE_UNFAVORITED,
1819
payload: agent.Articles.unfavorite(slug)
1920
})
2021
});

src/components/Editor.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,32 @@ import ListErrors from './ListErrors';
44
import React from 'react';
55
import agent from '../agent';
66
import { connect } from 'react-redux';
7+
import {
8+
ADD_TAG,
9+
EDITOR_PAGE_LOADED,
10+
REMOVE_TAG,
11+
ARTICLE_SUBMITTED,
12+
EDITOR_PAGE_UNLOADED,
13+
UPDATE_FIELD_EDITOR
14+
} from '../constants/actionTypes';
715

816
const mapStateToProps = state => ({
917
...state.editor
1018
});
1119

1220
const mapDispatchToProps = dispatch => ({
1321
onAddTag: () =>
14-
dispatch({ type: 'ADD_TAG' }),
22+
dispatch({ type: ADD_TAG }),
1523
onLoad: payload =>
16-
dispatch({ type: 'EDITOR_PAGE_LOADED', payload }),
24+
dispatch({ type: EDITOR_PAGE_LOADED, payload }),
1725
onRemoveTag: tag =>
18-
dispatch({ type: 'REMOVE_TAG', tag }),
26+
dispatch({ type: REMOVE_TAG, tag }),
1927
onSubmit: payload =>
20-
dispatch({ type: 'ARTICLE_SUBMITTED', payload }),
28+
dispatch({ type: ARTICLE_SUBMITTED, payload }),
2129
onUnload: payload =>
22-
dispatch({ type: 'EDITOR_PAGE_UNLOADED' }),
30+
dispatch({ type: EDITOR_PAGE_UNLOADED }),
2331
onUpdateField: (key, value) =>
24-
dispatch({ type: 'UPDATE_FIELD_EDITOR', key, value })
32+
dispatch({ type: UPDATE_FIELD_EDITOR, key, value })
2533
});
2634

2735
class Editor extends React.Component {

src/components/Home/MainView.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import ArticleList from '../ArticleList';
22
import React from 'react';
33
import agent from '../../agent';
44
import { connect } from 'react-redux';
5+
import { CHANGE_TAB } from '../../constants/actionTypes';
56

67
const YourFeedTab = props => {
78
if (props.token) {

src/components/Home/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import React from 'react';
44
import Tags from './Tags';
55
import agent from '../../agent';
66
import { connect } from 'react-redux';
7+
import {
8+
HOME_PAGE_LOADED,
9+
HOME_PAGE_UNLOADED,
10+
APPLY_TAG_FILTER
11+
} from '../../constants/actionTypes';
712

813
const Promise = global.Promise;
914

@@ -19,7 +24,7 @@ const mapDispatchToProps = dispatch => ({
1924
onLoad: (tab, pager, payload) =>
2025
dispatch({ type: 'HOME_PAGE_LOADED', tab, pager, payload }),
2126
onUnload: () =>
22-
dispatch({ type: 'HOME_PAGE_UNLOADED' })
27+
dispatch({ type: HOME_PAGE_UNLOADED })
2328
});
2429

2530
class Home extends React.Component {

src/components/ListPagination.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react';
22
import agent from '../agent';
33
import { connect } from 'react-redux';
4+
import { SET_PAGE } from '../constants/actionTypes';
45

56
const mapDispatchToProps = dispatch => ({
67
onSetPage: (page, payload) =>
7-
dispatch({ type: 'SET_PAGE', page, payload })
8+
dispatch({ type: SET_PAGE, page, payload })
89
});
910

1011
const ListPagination = props => {

0 commit comments

Comments
 (0)