Skip to content

Commit 4dbab9d

Browse files
authored
Merge pull request gothinkster#49 from ergun1017/master
fix list pagination with tag
2 parents c6d4069 + 4a7158a commit 4dbab9d

File tree

8 files changed

+29
-15
lines changed

8 files changed

+29
-15
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
@@ -7,7 +7,7 @@ const YourFeedTab = props => {
77
if (props.token) {
88
const clickHandler = ev => {
99
ev.preventDefault();
10-
props.onTabClick('feed', agent.Articles.feed());
10+
props.onTabClick('feed', agent.Articles.feed, agent.Articles.feed());
1111
}
1212

1313
return (
@@ -26,7 +26,7 @@ const YourFeedTab = props => {
2626
const GlobalFeedTab = props => {
2727
const clickHandler = ev => {
2828
ev.preventDefault();
29-
props.onTabClick('all', agent.Articles.all());
29+
props.onTabClick('all', agent.Articles.all, agent.Articles.all());
3030
};
3131
return (
3232
<li className="nav-item">
@@ -61,7 +61,7 @@ const mapStateToProps = state => ({
6161
});
6262

6363
const mapDispatchToProps = dispatch => ({
64-
onTabClick: (tab, payload) => dispatch({ type: 'CHANGE_TAB', tab, payload })
64+
onTabClick: (tab, pager, payload) => dispatch({ type: 'CHANGE_TAB', tab, pager, payload })
6565
});
6666

6767
const MainView = props => {
@@ -83,6 +83,7 @@ const MainView = props => {
8383
</div>
8484

8585
<ArticleList
86+
pager={props.pager}
8687
articles={props.articles}
8788
loading={props.loading}
8889
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
@@ -14,10 +14,10 @@ const mapStateToProps = state => ({
1414
});
1515

1616
const mapDispatchToProps = dispatch => ({
17-
onClickTag: (tag, payload) =>
18-
dispatch({ type: 'APPLY_TAG_FILTER', tag, payload }),
19-
onLoad: (tab, payload) =>
20-
dispatch({ type: 'HOME_PAGE_LOADED', tab, payload }),
17+
onClickTag: (tag, pager, payload) =>
18+
dispatch({ type: 'APPLY_TAG_FILTER', tag, pager, payload }),
19+
onLoad: (tab, pager, payload) =>
20+
dispatch({ type: 'HOME_PAGE_LOADED', tab, pager, payload }),
2121
onUnload: () =>
2222
dispatch({ type: 'HOME_PAGE_UNLOADED' })
2323
});
@@ -26,10 +26,10 @@ class Home extends React.Component {
2626
componentWillMount() {
2727
const tab = this.props.token ? 'feed' : 'all';
2828
const articlesPromise = this.props.token ?
29-
agent.Articles.feed() :
30-
agent.Articles.all();
29+
agent.Articles.feed :
30+
agent.Articles.all;
3131

32-
this.props.onLoad(tab, Promise.all([agent.Tags.getAll(), articlesPromise]));
32+
this.props.onLoad(tab, articlesPromise, Promise.all([agent.Tags.getAll(), articlesPromise()]));
3333
}
3434

3535
componentWillUnmount() {

src/components/ListPagination.js

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

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

2228
return (
2329
<nav>

src/components/Profile.js

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class Profile extends React.Component {
148148
</div>
149149

150150
<ArticleList
151+
pager={this.props.pager}
151152
articles={this.props.articles}
152153
articlesCount={this.props.articlesCount}
153154
state={this.props.currentPage} />

src/components/ProfileFavorites.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import agent from '../agent';
77
import { connect } from 'react-redux';
88

99
const mapDispatchToProps = dispatch => ({
10-
onLoad: (payload) =>
11-
dispatch({ type: 'PROFILE_FAVORITES_PAGE_LOADED', payload }),
10+
onLoad: (pager, payload) =>
11+
dispatch({ type: 'PROFILE_FAVORITES_PAGE_LOADED', pager, payload }),
1212
onUnload: () =>
1313
dispatch({ type: 'PROFILE_FAVORITES_PAGE_UNLOADED' })
1414
});
1515

1616
class ProfileFavorites extends Profile {
1717
componentWillMount() {
18-
this.props.onLoad(Promise.all([
18+
this.props.onLoad(page => agent.Articles.favoritedBy(this.props.params.username, page), Promise.all([
1919
agent.Profile.get(this.props.params.username),
2020
agent.Articles.favoritedBy(this.props.params.username)
2121
]));

src/reducers/articleList.js

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default (state = {}, action) => {
2727
case 'APPLY_TAG_FILTER':
2828
return {
2929
...state,
30+
pager: action.pager,
3031
articles: action.payload.articles,
3132
articlesCount: action.payload.articlesCount,
3233
tab: null,
@@ -36,6 +37,7 @@ export default (state = {}, action) => {
3637
case 'HOME_PAGE_LOADED':
3738
return {
3839
...state,
40+
pager: action.pager,
3941
tags: action.payload[0].tags,
4042
articles: action.payload[1].articles,
4143
articlesCount: action.payload[1].articlesCount,
@@ -47,6 +49,7 @@ export default (state = {}, action) => {
4749
case 'CHANGE_TAB':
4850
return {
4951
...state,
52+
pager: action.pager,
5053
articles: action.payload.articles,
5154
articlesCount: action.payload.articlesCount,
5255
tab: action.tab,
@@ -56,6 +59,7 @@ export default (state = {}, action) => {
5659
case 'APPLY_TAG_FILTER':
5760
return {
5861
...state,
62+
pager: action.pager,
5963
articles: action.payload.articles,
6064
articlesCount: action.payload.articlesCount,
6165
tab: null,
@@ -66,6 +70,7 @@ export default (state = {}, action) => {
6670
case 'PROFILE_FAVORITES_PAGE_LOADED':
6771
return {
6872
...state,
73+
pager: action.pager,
6974
articles: action.payload[1].articles,
7075
articlesCount: action.payload[1].articlesCount,
7176
currentPage: 0

0 commit comments

Comments
 (0)