Skip to content

Commit c7c38d0

Browse files
committed
align FetchMore component with fetchMore function
1 parent 20d3172 commit c7c38d0

File tree

4 files changed

+78
-103
lines changed

4 files changed

+78
-103
lines changed

src/Comment/CommentList/index.js

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,30 @@ import FetchMore from '../../FetchMore';
1111

1212
import './style.css';
1313

14-
const getConfiguration = (
15-
cursor,
16-
repositoryOwner,
17-
repositoryName,
18-
number,
19-
) => ({
20-
variables: {
21-
cursor,
22-
repositoryOwner,
23-
repositoryName,
24-
number,
25-
},
26-
updateQuery: (previousResult, { fetchMoreResult }) => {
27-
if (!fetchMoreResult) {
28-
return previousResult;
29-
}
14+
const updateQuery = (previousResult, { fetchMoreResult }) => {
15+
if (!fetchMoreResult) {
16+
return previousResult;
17+
}
3018

31-
return {
32-
...previousResult,
33-
repository: {
34-
...previousResult.repository,
35-
issue: {
36-
...previousResult.repository.issue,
37-
...fetchMoreResult.repository.issue,
38-
comments: {
39-
...previousResult.repository.issue.comments,
40-
...fetchMoreResult.repository.issue.comments,
41-
edges: [
42-
...previousResult.repository.issue.comments.edges,
43-
...fetchMoreResult.repository.issue.comments.edges,
44-
],
45-
},
19+
return {
20+
...previousResult,
21+
repository: {
22+
...previousResult.repository,
23+
issue: {
24+
...previousResult.repository.issue,
25+
...fetchMoreResult.repository.issue,
26+
comments: {
27+
...previousResult.repository.issue.comments,
28+
...fetchMoreResult.repository.issue.comments,
29+
edges: [
30+
...previousResult.repository.issue.comments.edges,
31+
...fetchMoreResult.repository.issue.comments.edges,
32+
],
4633
},
4734
},
48-
};
49-
},
50-
});
35+
},
36+
};
37+
};
5138

5239
const CommentList = ({ repositoryOwner, repositoryName, issue }) => (
5340
<Query
@@ -81,12 +68,13 @@ const CommentList = ({ repositoryOwner, repositoryName, issue }) => (
8168
hasNextPage={
8269
repository.issue.comments.pageInfo.hasNextPage
8370
}
84-
fetchMoreConfiguration={getConfiguration(
85-
repository.issue.comments.pageInfo.endCursor,
71+
variables={{
72+
cursor: repository.issue.comments.pageInfo.endCursor,
8673
repositoryOwner,
8774
repositoryName,
88-
issue.number,
89-
)}
75+
number: issue.number,
76+
}}
77+
updateQuery={updateQuery}
9078
fetchMore={fetchMore}
9179
>
9280
Comments

src/FetchMore/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import './style.css';
88
const FetchMore = ({
99
loading,
1010
hasNextPage,
11-
fetchMoreConfiguration,
11+
variables,
12+
updateQuery,
1213
fetchMore,
1314
children,
1415
}) => (
@@ -19,7 +20,7 @@ const FetchMore = ({
1920
hasNextPage && (
2021
<ButtonUnobtrusive
2122
className="FetchMore-button"
22-
onClick={() => fetchMore(fetchMoreConfiguration)}
23+
onClick={() => fetchMore({ variables, updateQuery })}
2324
>
2425
{`More ${children}`}
2526
</ButtonUnobtrusive>

src/Issue/IssueList/index.js

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -57,39 +57,26 @@ const prefetchIssues = (
5757
}
5858
};
5959

60-
const getConfiguration = (
61-
cursor,
62-
repositoryOwner,
63-
repositoryName,
64-
showState,
65-
) => ({
66-
variables: {
67-
cursor,
68-
repositoryOwner,
69-
repositoryName,
70-
kindOfIssue: KIND_OF_ISSUES[showState],
71-
},
72-
updateQuery: (previousResult, { fetchMoreResult }) => {
73-
if (!fetchMoreResult) {
74-
return previousResult;
75-
}
76-
77-
return {
78-
...previousResult,
79-
repository: {
80-
...previousResult.repository,
81-
issues: {
82-
...previousResult.repository.issues,
83-
...fetchMoreResult.repository.issues,
84-
edges: [
85-
...previousResult.repository.issues.edges,
86-
...fetchMoreResult.repository.issues.edges,
87-
],
88-
},
60+
const updateQuery = (previousResult, { fetchMoreResult }) => {
61+
if (!fetchMoreResult) {
62+
return previousResult;
63+
}
64+
65+
return {
66+
...previousResult,
67+
repository: {
68+
...previousResult.repository,
69+
issues: {
70+
...previousResult.repository.issues,
71+
...fetchMoreResult.repository.issues,
72+
edges: [
73+
...previousResult.repository.issues.edges,
74+
...fetchMoreResult.repository.issues.edges,
75+
],
8976
},
90-
};
91-
},
92-
});
77+
},
78+
};
79+
};
9380

9481
const Issues = ({
9582
repositoryOwner,
@@ -185,12 +172,13 @@ const IssuesList = ({
185172
<FetchMore
186173
loading={loading}
187174
hasNextPage={repository.issues.pageInfo.hasNextPage}
188-
fetchMoreConfiguration={getConfiguration(
189-
repository.issues.pageInfo.endCursor,
175+
variables={{
176+
cursor: repository.issues.pageInfo.endCursor,
190177
repositoryOwner,
191178
repositoryName,
192-
showState,
193-
)}
179+
kindOfIssue: KIND_OF_ISSUES[showState],
180+
}}
181+
updateQuery={updateQuery}
194182
fetchMore={fetchMore}
195183
>
196184
Issues

src/Repository/RepositoryList/index.js

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,29 @@ import FetchMore from '../../FetchMore';
77

88
import '../style.css';
99

10-
const getConfiguration = (cursor, entry) => ({
11-
variables: {
12-
cursor,
13-
},
14-
updateQuery: (previousResult, { fetchMoreResult }) => {
15-
if (!fetchMoreResult) {
16-
return previousResult;
17-
}
10+
const getUpdateQuery = entry => (
11+
previousResult,
12+
{ fetchMoreResult },
13+
) => {
14+
if (!fetchMoreResult) {
15+
return previousResult;
16+
}
1817

19-
return {
20-
...previousResult,
21-
[entry]: {
22-
...previousResult[entry],
23-
repositories: {
24-
...previousResult[entry].repositories,
25-
...fetchMoreResult[entry].repositories,
26-
edges: [
27-
...previousResult[entry].repositories.edges,
28-
...fetchMoreResult[entry].repositories.edges,
29-
],
30-
},
18+
return {
19+
...previousResult,
20+
[entry]: {
21+
...previousResult[entry],
22+
repositories: {
23+
...previousResult[entry].repositories,
24+
...fetchMoreResult[entry].repositories,
25+
edges: [
26+
...previousResult[entry].repositories.edges,
27+
...fetchMoreResult[entry].repositories.edges,
28+
],
3129
},
32-
};
33-
},
34-
});
30+
},
31+
};
32+
};
3533

3634
const RepositoryList = ({
3735
entry,
@@ -54,10 +52,10 @@ const RepositoryList = ({
5452
<FetchMore
5553
loading={loading}
5654
hasNextPage={repositories.pageInfo.hasNextPage}
57-
fetchMoreConfiguration={getConfiguration(
58-
repositories.pageInfo.endCursor,
59-
entry,
60-
)}
55+
variables={{
56+
cursor: repositories.pageInfo.endCursor,
57+
}}
58+
updateQuery={getUpdateQuery(entry)}
6159
fetchMore={fetchMore}
6260
>
6361
Repositories

0 commit comments

Comments
 (0)