Skip to content

Commit 2c9fa98

Browse files
authored
Merge branch 'master' into fix/constants
2 parents 3f0dc2c + 390c2f1 commit 2c9fa98

9 files changed

+29
-16
lines changed

src/components/ArticleList.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const ArticleList = props => {
3030
}
3131

3232
<ListPagination
33+
pager={props.pager}
3334
articlesCount={props.articlesCount}
3435
currentPage={props.currentPage} />
3536
</div>

src/components/Home/MainView.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const YourFeedTab = props => {
88
if (props.token) {
99
const clickHandler = ev => {
1010
ev.preventDefault();
11-
props.onTabClick('feed', agent.Articles.feed());
11+
props.onTabClick('feed', agent.Articles.feed, agent.Articles.feed());
1212
}
1313

1414
return (
@@ -27,7 +27,7 @@ const YourFeedTab = props => {
2727
const GlobalFeedTab = props => {
2828
const clickHandler = ev => {
2929
ev.preventDefault();
30-
props.onTabClick('all', agent.Articles.all());
30+
props.onTabClick('all', agent.Articles.all, agent.Articles.all());
3131
};
3232
return (
3333
<li className="nav-item">
@@ -62,7 +62,7 @@ const mapStateToProps = state => ({
6262
});
6363

6464
const mapDispatchToProps = dispatch => ({
65-
onTabClick: (tab, payload) => dispatch({ type: CHANGE_TAB, tab, payload })
65+
onTabClick: (tab, pager, payload) => dispatch({ type: 'CHANGE_TAB', tab, pager, payload })
6666
});
6767

6868
const MainView = props => {
@@ -84,6 +84,7 @@ const MainView = props => {
8484
</div>
8585

8686
<ArticleList
87+
pager={props.pager}
8788
articles={props.articles}
8889
loading={props.loading}
8990
articlesCount={props.articlesCount}

src/components/Home/Tags.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const Tags = props => {
1010
tags.map(tag => {
1111
const handleClick = ev => {
1212
ev.preventDefault();
13-
props.onClickTag(tag, agent.Articles.byTag(tag));
13+
props.onClickTag(tag, page => agent.Articles.byTag(tag, page), agent.Articles.byTag(tag));
1414
};
1515

1616
return (

src/components/Home/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ const mapStateToProps = state => ({
1919
});
2020

2121
const mapDispatchToProps = dispatch => ({
22-
onClickTag: (tag, payload) =>
23-
dispatch({ type: APPLY_TAG_FILTER, tag, payload }),
24-
onLoad: (tab, payload) =>
25-
dispatch({ type: HOME_PAGE_LOADED, tab, payload }),
22+
onClickTag: (tag, pager, payload) =>
23+
dispatch({ type: 'APPLY_TAG_FILTER', tag, pager, payload }),
24+
onLoad: (tab, pager, payload) =>
25+
dispatch({ type: 'HOME_PAGE_LOADED', tab, pager, payload }),
2626
onUnload: () =>
2727
dispatch({ type: HOME_PAGE_UNLOADED })
2828
});
@@ -31,10 +31,10 @@ class Home extends React.Component {
3131
componentWillMount() {
3232
const tab = this.props.token ? 'feed' : 'all';
3333
const articlesPromise = this.props.token ?
34-
agent.Articles.feed() :
35-
agent.Articles.all();
34+
agent.Articles.feed :
35+
agent.Articles.all;
3636

37-
this.props.onLoad(tab, Promise.all([agent.Tags.getAll(), articlesPromise]));
37+
this.props.onLoad(tab, articlesPromise, Promise.all([agent.Tags.getAll(), articlesPromise()]));
3838
}
3939

4040
componentWillUnmount() {

src/components/ListPagination.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ const ListPagination = props => {
1818
range.push(i);
1919
}
2020

21-
const setPage = page => props.onSetPage(page, agent.Articles.all(page));
21+
const setPage = page => {
22+
if(props.pager) {
23+
props.onSetPage(page, props.pager(page));
24+
}else {
25+
props.onSetPage(page, agent.Articles.all(page))
26+
}
27+
};
2228

2329
return (
2430
<nav>

src/components/Profile.js

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class Profile extends React.Component {
154154
</div>
155155

156156
<ArticleList
157+
pager={this.props.pager}
157158
articles={this.props.articles}
158159
articlesCount={this.props.articlesCount}
159160
state={this.props.currentPage} />

src/components/ProfileFavorites.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import {
1111
} from '../constants/actionTypes';
1212

1313
const mapDispatchToProps = dispatch => ({
14-
onLoad: (payload) =>
15-
dispatch({ type: PROFILE_FAVORITES_PAGE_LOADED, payload }),
14+
onLoad: (pager, payload) =>
15+
dispatch({ type: 'PROFILE_FAVORITES_PAGE_LOADED', pager, payload }),
1616
onUnload: () =>
1717
dispatch({ type: PROFILE_FAVORITES_PAGE_UNLOADED })
1818
});
1919

2020
class ProfileFavorites extends Profile {
2121
componentWillMount() {
22-
this.props.onLoad(Promise.all([
22+
this.props.onLoad(page => agent.Articles.favoritedBy(this.props.params.username, page), Promise.all([
2323
agent.Profile.get(this.props.params.username),
2424
agent.Articles.favoritedBy(this.props.params.username)
2525
]));

src/reducers/articleList.js

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default (state = {}, action) => {
3939
case APPLY_TAG_FILTER:
4040
return {
4141
...state,
42+
pager: action.pager,
4243
articles: action.payload.articles,
4344
articlesCount: action.payload.articlesCount,
4445
tab: null,
@@ -48,6 +49,7 @@ export default (state = {}, action) => {
4849
case HOME_PAGE_LOADED:
4950
return {
5051
...state,
52+
pager: action.pager,
5153
tags: action.payload[0].tags,
5254
articles: action.payload[1].articles,
5355
articlesCount: action.payload[1].articlesCount,
@@ -59,6 +61,7 @@ export default (state = {}, action) => {
5961
case CHANGE_TAB:
6062
return {
6163
...state,
64+
pager: action.pager,
6265
articles: action.payload.articles,
6366
articlesCount: action.payload.articlesCount,
6467
tab: action.tab,
@@ -69,6 +72,7 @@ export default (state = {}, action) => {
6972
case PROFILE_FAVORITES_PAGE_LOADED:
7073
return {
7174
...state,
75+
pager: action.pager,
7276
articles: action.payload[1].articles,
7377
articlesCount: action.payload[1].articlesCount,
7478
currentPage: 0

src/store.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ const getMiddleware = () => {
1212
}
1313
}
1414

15-
const store = createStore(reducer, getMiddleware());
15+
const store = createStore(reducer, getMiddleware(), window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__())
1616

1717
export default store;

0 commit comments

Comments
 (0)