From fefc7ac76bbbaf19656b64eca18dc1e1d1e0daa8 Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Thu, 10 Oct 2019 14:53:13 +0100 Subject: [PATCH] End of chapter 24 --- .idea/workspace.xml | 37 ++++++++++++++++++++++++++------ src/App.js | 37 ++++++++++++++++++++++++++------ src/components/repos/RepoItem.js | 17 +++++++++++++++ src/components/repos/Repos.js | 12 +++++++++++ src/components/users/User.js | 9 ++++++-- 5 files changed, 96 insertions(+), 16 deletions(-) create mode 100644 src/components/repos/RepoItem.js create mode 100644 src/components/repos/Repos.js diff --git a/.idea/workspace.xml b/.idea/workspace.xml index bd3fb5e..43df2d2 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,10 @@ + + + + + + + @@ -36,9 +45,10 @@ - - - + + + + @@ -55,7 +65,8 @@ - + + @@ -102,7 +113,11 @@ 1569429914875 - + + + + + 1569512995385 @@ -181,7 +196,14 @@ - @@ -212,6 +234,7 @@ - \ No newline at end of file diff --git a/src/App.js b/src/App.js index 90b15f9..8a5f5f9 100644 --- a/src/App.js +++ b/src/App.js @@ -6,7 +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 User from "./components/users/User"; import axios from "axios"; import "./App.css"; @@ -17,7 +17,8 @@ class App extends Component { users: [], loading: false, alert: null, - user: {} + user: {}, + repos: [] }; } @@ -52,6 +53,18 @@ class App extends Component { console.log(res.data); this.setState({ user: res.data, loading: false }); }; + + getUserRepos = async username => { + this.setState({ loading: true }); + const res = await axios.get( + `https://api.github.com/users/${username}/repos?per_page=5&sort=created:asc&client_id=${ + process.env.REACT_APP_GITHUB_CLIENT_ID + }&client_secret=${process.env.REACT_APP_GITHUB_CLIENT_SECRET}` + ); + console.log(res.data); + this.setState({ repos: res.data, loading: false }); + }; + // Clear Users from State clearUsers = () => { @@ -67,7 +80,7 @@ class App extends Component { }; render() { - const { users, user, loading } = this.state; + const { users, user, loading, repos } = this.state; return (
@@ -92,10 +105,20 @@ class App extends Component { )} /> - ( - - - )}/> + ( + + )} + />
diff --git a/src/components/repos/RepoItem.js b/src/components/repos/RepoItem.js new file mode 100644 index 0000000..c1071f6 --- /dev/null +++ b/src/components/repos/RepoItem.js @@ -0,0 +1,17 @@ +import React from "react"; +import PropTypes from "prop-types"; + +const RepoItem = ({ repo }) => { + return ( +
+

+ {repo.name} +

+
+ ); +}; + +RepoItem.propTypes = { + repo: PropTypes.object.isRequired +}; +export default RepoItem; diff --git a/src/components/repos/Repos.js b/src/components/repos/Repos.js new file mode 100644 index 0000000..6072de1 --- /dev/null +++ b/src/components/repos/Repos.js @@ -0,0 +1,12 @@ +import React from "react"; +import RepoItem from "./RepoItem"; +import PropTypes from "prop-types"; + +const Repos = ({ repos }) => { + return repos.map(repo => ); +}; + +Repos.propTypes = { + repos: PropTypes.array.isRequired +}; +export default Repos; diff --git a/src/components/users/User.js b/src/components/users/User.js index da6f203..cdd754e 100644 --- a/src/components/users/User.js +++ b/src/components/users/User.js @@ -1,17 +1,21 @@ import React, { Component, Fragment } from "react"; import Spinner from "../layout/Spinner"; +import Repos from '../repos/Repos'; import PropTypes from "prop-types"; import { Link } from "react-router-dom"; class User extends Component { componentDidMount() { this.props.getUser(this.props.match.params.login); + this.props.getUserRepos(this.props.match.params.login); } static propTypes = { loading: PropTypes.bool, user: PropTypes.object.isRequired, - getUser: PropTypes.func.isRequired + getUser: PropTypes.func.isRequired, + getUserRepos: PropTypes.func.isRequired, + repos: PropTypes.array.isRequired }; render() { @@ -31,7 +35,7 @@ class User extends Component { hireable } = this.props.user; - const { loading } = this.props; + const { loading, repos } = this.props; if (loading) return ; @@ -101,6 +105,7 @@ class User extends Component {
Public Repos: {public_repos}
Public Gists: {public_gists}
+ ); }