Skip to content

Commit

Permalink
Merge pull request #4 from facn5/getData
Browse files Browse the repository at this point in the history
Get data
  • Loading branch information
Bear-Coding authored Apr 24, 2019
2 parents bd8ca26 + 1389d07 commit 597cb38
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/components/button/button.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
button {
color: red;
height: 30px;
width:80px;
}
2 changes: 1 addition & 1 deletion src/components/button/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import './button.css';
class Button extends React.Component {
render() {
return (
<button></button>
<button>Compare</button>
);
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/components/card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@ import React from 'react';
import './style.css';
import GInfo from "./userinfo";
import Statistics from "./userstatistics";
import { getData, API_BASE } from "../../tools/getData";

class PortfolioCard extends React.Component {
state = {
data: {}
};


componentDidMount() {
const username = "";
const url = `${API_BASE}/users/${username}`;

getData(url).then(data => this.setState({ data }));
}

render() {
return (
<div>
Expand Down
8 changes: 4 additions & 4 deletions src/components/card/userinfo/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import './style.css';

import Image from "../../image"
class GInfo extends React.Component {
render() {
return (
<div>
<img></img>
<h1></h1>
<div className="gInfo">
<Image source="https://avatars0.githubusercontent.com/u/21008707?v=4"/>
<h1>Shadi</h1>
</div>
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/card/userinfo/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.gInfo{
border-radius: 10px;

}
2 changes: 1 addition & 1 deletion src/components/card/userstatistics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import './style.css';
class Statistics extends React.Component {
render() {
return (
<div>
<div id="table">
<table>
<tr>
<td>Projects count</td>
Expand Down
2 changes: 1 addition & 1 deletion src/components/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import './style.css';
class Image extends React.Component {
render() {
return (
<img />
<img src={this.props.source}/>
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import './style.css';
class Input extends React.Component {
render() {
return (
<input />
<p/>,<input onChange={(e) => this.props.updateUserOne(e.target.value)} />
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>React stuff</title>
<title>GitBattleHUB</title>
</head>

<body>
<div id="🤡"></div>
<script src="index.js"></script>
</body>

</html>
</html>
22 changes: 16 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ import Input from './components/input';
import Button from './components/button/button.js'
import PortfolioCard from './components/card';
import Image from './components/image'

ReactDOM.render(
<div>
<div class="inputs-container">
<Input /> <Button /> <Input />
import "./style.css";
class App extends React.Component {
state = {
userOne:"",
userTwo:"",
}
render(){
return(<div>
<div className="inputs-container">
<Input updateUser={(value) => this.setState({ userOne: value})}/> <Button /> <Input updateUser={(value) => this.setState({ userOne: value})} />
</div>
<div className="cards-container">
<PortfolioCard /> <Image /> <PortfolioCard />
</div>
, document.getElementById('🤡'));
</div>
)}}


ReactDOM.render(<App/>, document.getElementById('🤡'));
36 changes: 36 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
body{
background-color:cyan;
}
input{

}
.cards-container{
display:flex;
flex-direction: row;
justify-content:space-evenly;
}
.inputs-container{
display:flex;
flex-direction: row;
justify-content:space-evenly;
}
#table {
border-collapse: collapse;
width: 100%;
}

#table td, #table th {
border: 1px solid #ddd;
padding: 8px;
}


#table tr:hover {background-color: #ddd;}

#table th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #4CAF50;
color: white;
}
19 changes: 19 additions & 0 deletions src/tools/getData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// import { accessToken } from "../../token";
export const accessToken = "6953b440ab762a5d9de0112d3be3f6a179533e0e";
export const API_BASE = "https://api.github.com";

const checkResponse = response => {
if (response.status !== 200) {
return(`Error with the request! ${response.status}`);

}
return response.json();
};

export const getData = url => {
return fetch(`${url}?access_token=${accessToken}`)
.then(checkResponse)
.catch(err => {
throw new Error(`fetch getUserData failed ${err}`);
});
};

0 comments on commit 597cb38

Please sign in to comment.