File tree Expand file tree Collapse file tree 4 files changed +97
-0
lines changed
Repository/RepositoryList Expand file tree Collapse file tree 4 files changed +97
-0
lines changed Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change 1+ import Issues from './IssueList' ;
2+
3+ export default Issues ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import React, { Fragment } from 'react';
22
33import FetchMore from '../../FetchMore' ;
44import RepositoryItem from '../RepositoryItem' ;
5+ import Issues from '../../Issue' ;
56
67import '../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
You can’t perform that action at this time.
0 commit comments