Skip to content

Commit 0ba7863

Browse files
committed
display real data from github api
1 parent 0d83b00 commit 0ba7863

File tree

5 files changed

+88
-13
lines changed

5 files changed

+88
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
npm-debug.log*
2222
yarn-debug.log*
2323
yarn-error.log*
24+
debug.log

src/Components/Repo.js

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import moment from 'moment'
4+
// import 'moment/locale/es' // without this line it didn't work
5+
// moment.locale('es')
6+
37
import {
48
withStyles,
59
Typography,
610
ButtonBase,
7-
Grid,
811
Paper,
12+
Grid,
913
Chip,
14+
Link,
1015

1116
} from '@material-ui/core';
1217

@@ -32,44 +37,76 @@ const styles = theme => ({
3237
},
3338
chip: {
3439
margin: theme.spacing.unit,
40+
},
41+
link: {
42+
margin: theme.spacing.unit,
3543
}
3644
});
3745

3846

3947

40-
const Repo = ({ classes }) => {
48+
const Repo = ({
49+
classes,
50+
avatar_url,
51+
name,
52+
html_url,
53+
owner,
54+
description,
55+
stargazers_count,
56+
open_issues_count,
57+
// issues_url,
58+
// stargazers_url,
59+
created_at
60+
61+
}) => {
62+
63+
// console.log("last 30 days is: ", moment(created_at).fromNow())
4164

4265
return (
4366
<div className={ classes.root }>
4467
<Paper className={ classes.paper }>
4568
<Grid container spacing={ 16 }>
4669
<Grid item>
4770
<ButtonBase className={ classes.image }>
48-
<img className={ classes.img } alt="Owner Avatar" src="" />
71+
<a href={ ` https://github.com/${ owner } ` } target="_blank" rel="noopener noreferrer">
72+
<img className={ classes.img } alt="Owner Avatar" src={ ` ${ avatar_url } ` } />
73+
</a>
4974
</ButtonBase>
5075
</Grid>
5176
<Grid item xs={ 12 } sm container>
5277
<Grid item xs container direction="column" spacing={ 24 }>
5378
<Grid item xs>
54-
<Typography gutterBottom={ true } variant="h3" color='textPrimary'>
55-
Repository name
79+
<Typography gutterBottom={ true } variant="h3">
80+
<Link
81+
href={ html_url }
82+
color="inherit"
83+
target="_blank"
84+
rel="noopener noreferrer"
85+
underline="hover"
86+
className={ classes.link }
87+
>
88+
{ name }
89+
</Link>
5690
</Typography>
57-
<Typography gutterBottom={ true } variant="headline">Repository description</Typography>
91+
<Typography gutterBottom={ true } variant="headline">{ description }</Typography>
5892
<Chip
59-
label="Number of stars"
93+
label= { ` Stars: ${ stargazers_count } ` }
6094
className={ classes.chip }
6195
href="#chip"
6296
clickable
6397
variant="outlined"
6498
/>
6599
<Chip
66-
label="Number of issues"
100+
label={ ` Issues: ${ open_issues_count } ` }
67101
className={ classes.chip }
68-
href="#chip"
69102
clickable
70103
variant="outlined"
71104
/>
72-
<Typography color="primary" inline={ true }>Submitted 30 day ago By Tenserflow</Typography>
105+
<Typography
106+
color="primary"
107+
inline={ true }>
108+
Submitted { moment(created_at).fromNow() } By { owner }
109+
</Typography>
73110
</Grid>
74111
</Grid>
75112
</Grid>

src/Containers/App.css

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.App-logo {
6+
animation: App-logo-spin infinite 20s linear;
7+
height: 40vmin;
8+
pointer-events: none;
9+
}
10+
11+
.App-header {
12+
background-color: #282c34;
13+
min-height: 100vh;
14+
display: flex;
15+
flex-direction: column;
16+
align-items: center;
17+
justify-content: center;
18+
font-size: calc(10px + 2vmin);
19+
color: white;
20+
}
21+
22+
.App-link {
23+
color: #61dafb;
24+
}
25+
26+
@keyframes App-logo-spin {
27+
from {
28+
transform: rotate(0deg);
29+
}
30+
to {
31+
transform: rotate(360deg);
32+
}
33+
}

src/Containers/App.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import React, { Component } from 'react';
44
import RepoList from '../Components/RepoList';
55
import axios from 'axios';
6+
import moment from 'moment';
67

78

89
class App extends Component {
@@ -18,12 +19,14 @@ class App extends Component {
1819
componentDidMount(){
1920
// Getting the data from Github API
2021

22+
const DATE_30_DAYS_BEFORE = moment().subtract(30, 'days').format('YYYY-MM-DD')
23+
2124
axios.get(
22-
'https://api.github.com/search/repositories?q=created:>2017-10-22&sort=stars&order=desc&page=3'
25+
` https://api.github.com/search/repositories?q=created:>${ DATE_30_DAYS_BEFORE }&sort=stars&order=desc&page=3 `
2326
)
2427

2528
.then(resp => {
26-
console.log(resp);
29+
// console.log(resp);
2730
this.setState({
2831
repo: resp.data.items,
2932
});

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import './index.css';
4-
import App from './App';
4+
import App from './Containers/App';
5+
// import Repo from './Components/Repo';
56
import * as serviceWorker from './serviceWorker';
67

78
ReactDOM.render(<App />, document.getElementById('root'));

0 commit comments

Comments
 (0)