Skip to content

Commit f81ad70

Browse files
committed
refactor comment module to match other modules
1 parent 3c96f76 commit f81ad70

File tree

5 files changed

+54
-36
lines changed

5 files changed

+54
-36
lines changed

src/Comment/CommentList/index.js

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { Fragment } from 'react';
22
import { Query } from 'react-apollo';
33

44
import { GET_COMMENTS_OF_ISSUE } from './queries';
@@ -36,7 +36,7 @@ const updateQuery = (previousResult, { fetchMoreResult }) => {
3636
};
3737
};
3838

39-
const CommentList = ({ repositoryOwner, repositoryName, issue }) => (
39+
const Comments = ({ repositoryOwner, repositoryName, issue }) => (
4040
<Query
4141
query={GET_COMMENTS_OF_ISSUE}
4242
variables={{
@@ -58,33 +58,51 @@ const CommentList = ({ repositoryOwner, repositoryName, issue }) => (
5858
}
5959

6060
return (
61-
<div className="CommentList">
62-
{repository.issue.comments.edges.map(({ node }) => (
63-
<CommentItem key={node.id} comment={node} />
64-
))}
65-
66-
<FetchMore
61+
<Fragment>
62+
<CommentList
63+
comments={repository.issue.comments}
6764
loading={loading}
68-
hasNextPage={
69-
repository.issue.comments.pageInfo.hasNextPage
70-
}
71-
variables={{
72-
cursor: repository.issue.comments.pageInfo.endCursor,
73-
repositoryOwner,
74-
repositoryName,
75-
number: issue.number,
76-
}}
77-
updateQuery={updateQuery}
65+
number={issue.number}
66+
repositoryOwner={repositoryOwner}
67+
repositoryName={repositoryName}
7868
fetchMore={fetchMore}
79-
>
80-
Comments
81-
</FetchMore>
69+
/>
8270

8371
<CommentAdd issueId={repository.issue.id} />
84-
</div>
72+
</Fragment>
8573
);
8674
}}
8775
</Query>
8876
);
8977

90-
export default CommentList;
78+
const CommentList = ({
79+
comments,
80+
loading,
81+
repositoryOwner,
82+
repositoryName,
83+
number,
84+
fetchMore,
85+
}) => (
86+
<div className="CommentList">
87+
{comments.edges.map(({ node }) => (
88+
<CommentItem key={node.id} comment={node} />
89+
))}
90+
91+
<FetchMore
92+
loading={loading}
93+
hasNextPage={comments.pageInfo.hasNextPage}
94+
variables={{
95+
cursor: comments.pageInfo.endCursor,
96+
repositoryOwner,
97+
repositoryName,
98+
number,
99+
}}
100+
updateQuery={updateQuery}
101+
fetchMore={fetchMore}
102+
>
103+
Comments
104+
</FetchMore>
105+
</div>
106+
);
107+
108+
export default Comments;

src/Comment/CommentList/queries.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const GET_COMMENTS_OF_ISSUE = gql`
1010
repository(name: $repositoryName, owner: $repositoryOwner) {
1111
issue(number: $number) {
1212
id
13-
comments(first: 5, after: $cursor) {
13+
comments(first: 1, after: $cursor) {
1414
edges {
1515
node {
1616
id

src/Comment/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import CommentList from './CommentList';
1+
import Comments from './CommentList';
22

3-
export default CommentList;
3+
export default Comments;

src/Issue/IssueItem/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import React from 'react';
22
import { withState } from 'recompose';
33

44
import Button from '../../Button';
5-
import CommentList from '../../Comment';
5+
import Comments from '../../Comment';
66
import Link from '../../Link';
77

88
import './style.css';
99

10-
const Issue = ({
10+
const IssueItem = ({
1111
issue,
1212
repositoryOwner,
1313
repositoryName,
@@ -26,7 +26,7 @@ const Issue = ({
2626
<div dangerouslySetInnerHTML={{ __html: issue.bodyHTML }} />
2727

2828
{isShowComments && (
29-
<CommentList
29+
<Comments
3030
repositoryOwner={repositoryOwner}
3131
repositoryName={repositoryName}
3232
issue={issue}
@@ -37,5 +37,5 @@ const Issue = ({
3737
);
3838

3939
export default withState('isShowComments', 'onShowComments', false)(
40-
Issue,
40+
IssueItem,
4141
);

src/Issue/IssueList/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ const Issues = ({
119119

120120
return (
121121
<IssuesList
122-
showState={showState}
123-
repositoryOwner={repositoryOwner}
124-
repositoryName={repositoryName}
125122
issues={repository.issues}
126123
loading={loading}
124+
repositoryOwner={repositoryOwner}
125+
repositoryName={repositoryName}
126+
showState={showState}
127127
fetchMore={fetchMore}
128128
/>
129129
);
@@ -161,11 +161,11 @@ const IssueFilter = ({
161161
);
162162

163163
const IssuesList = ({
164-
showState,
165-
repositoryOwner,
166-
repositoryName,
167164
issues,
168165
loading,
166+
repositoryOwner,
167+
repositoryName,
168+
showState,
169169
fetchMore,
170170
}) => (
171171
<div className="IssueList">

0 commit comments

Comments
 (0)