diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ff60c09..656d83c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,13 +2,10 @@ - - + - - - + @@ -201,6 +205,7 @@ - \ No newline at end of file diff --git a/src/App.js b/src/App.js index c8c8fec..90b15f9 100644 --- a/src/App.js +++ b/src/App.js @@ -6,6 +6,7 @@ import Users from "./components/users/Users"; import Search from "./components/users/Search"; import Alert from "./components/layout/Alert"; import About from "./components/pages/About"; +import User from './components/users/User'; import axios from "axios"; import "./App.css"; @@ -15,7 +16,8 @@ class App extends Component { this.state = { users: [], loading: false, - alert: null + alert: null, + user: {} }; } @@ -38,6 +40,18 @@ class App extends Component { this.setState({ users: res.data.items, loading: false }); }; + // Get Single user + + getUser = async username => { + this.setState({ loading: true }); + const res = await axios.get( + `https://api.github.com/users/${username}?client_id=${ + process.env.REACT_APP_GITHUB_CLIENT_ID + }&client_secret=${process.env.REACT_APP_GITHUB_CLIENT_SECRET}` + ); + console.log(res.data); + this.setState({ user: res.data, loading: false }); + }; // Clear Users from State clearUsers = () => { @@ -53,7 +67,7 @@ class App extends Component { }; render() { - const { users, loading } = this.state; + const { users, user, loading } = this.state; return (
@@ -77,7 +91,11 @@ class App extends Component { )} /> - + + ( + + + )}/>
diff --git a/src/components/users/User.js b/src/components/users/User.js new file mode 100644 index 0000000..d388db5 --- /dev/null +++ b/src/components/users/User.js @@ -0,0 +1,29 @@ +import React, { Component } from "react"; + +class User extends Component { + componentDidMount() { + this.props.getUser(this.props.match.params.login); + } + + render() { + const { + name, + avatar_url, + location, + bio, + blog, + login, + html_url, + followers, + following, + public_repos, + public_gists, + hireable + } = this.props.user; + + const { loading } = this.props; + return
{name}
; + } +} + +export default User; diff --git a/src/components/users/UserItem.js b/src/components/users/UserItem.js index 95d29a0..bf4bc71 100644 --- a/src/components/users/UserItem.js +++ b/src/components/users/UserItem.js @@ -1,5 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; +import {Link} from 'react-router-dom'; const UserItem = props => { const { login, avatar_url, html_url } = props.user; @@ -9,7 +10,7 @@ const UserItem = props => {

{login}

- More + More
);