Skip to content

Commit 6781b48

Browse files
committed
11-Implementing the Issues Feature: Setup
1 parent 3ab9c75 commit 6781b48

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

src/Issue/IssueItem/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
3+
import Link from '../../Link';
4+
5+
import './style.css';
6+
7+
const IssueItem = ({ issue }) => (
8+
<div className="IssueItem">
9+
{/* placeholder to add a show/hide comment button later */}
10+
11+
<div className="IssueItem-content">
12+
<h3>
13+
<Link href={issue.url}>{issue.title}</Link>
14+
</h3>
15+
<div dangerouslySetInnerHTML={{ __html: issue.bodyHTML }} />
16+
17+
{/* placeholder to render a list of comments later */}
18+
</div>
19+
</div>
20+
);
21+
22+
export default IssueItem;

src/Issue/IssueList/index.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import React from 'react';
2+
import { Query } from 'react-apollo';
3+
import gql from 'graphql-tag';
4+
5+
import IssueItem from '../IssueItem';
6+
import Loading from '../../Loading';
7+
import ErrorMessage from '../../Error';
8+
9+
import './style.css';
10+
11+
const GET_ISSUES_OF_REPOSITORY = gql`
12+
query($repositoryOwner: String!, $repositoryName: String!) {
13+
repository(name: $repositoryName, owner: $repositoryOwner) {
14+
issues(first: 5) {
15+
edges {
16+
node {
17+
id
18+
number
19+
state
20+
title
21+
url
22+
bodyHTML
23+
}
24+
}
25+
}
26+
}
27+
}
28+
`;
29+
30+
const Issues = ({ repositoryOwner, repositoryName }) => (
31+
<Query
32+
query={GET_ISSUES_OF_REPOSITORY}
33+
variables={{
34+
repositoryOwner,
35+
repositoryName,
36+
}}
37+
>
38+
{({ data, loading, error }) => {
39+
if (error) {
40+
return <ErrorMessage error={error} />;
41+
}
42+
43+
const { repository } = data;
44+
45+
if (loading && !repository) {
46+
return <Loading />;
47+
}
48+
49+
if (!repository.issues.edges.length) {
50+
return <div className="IssueList">No issues ...</div>;
51+
}
52+
53+
return <IssueList issues={repository.issues} />;
54+
}}
55+
</Query>
56+
);
57+
58+
const IssueList = ({ issues }) => (
59+
<div className="IssueList">
60+
{issues.edges.map(({ node }) => (
61+
<IssueItem key={node.id} issue={node} />
62+
))}
63+
</div>
64+
);
65+
66+
export default Issues;

src/Issue/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Issues from './IssueList';
2+
3+
export default Issues;

src/Repository/RepositoryList/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Fragment } from 'react';
22

33
import FetchMore from '../../FetchMore';
44
import RepositoryItem from '../RepositoryItem';
5+
import Issues from '../../Issue';
56

67
import '../style.css';
78

@@ -39,6 +40,11 @@ const RepositoryList = ({
3940
{repositories.edges.map(({ node }) => (
4041
<div key={node.id} className="RepositoryItem">
4142
<RepositoryItem {...node} />
43+
44+
<Issues
45+
repositoryName={node.name}
46+
repositoryOwner={node.owner.login}
47+
/>
4248
</div>
4349
))}
4450

0 commit comments

Comments
 (0)