diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index e3b777b..85e666b 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,8 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -37,17 +59,17 @@
-
+
-
+
@@ -61,12 +83,13 @@
+
-
+
@@ -90,18 +113,6 @@
-
-
-
@@ -133,6 +144,8 @@
+
+
1569512995385
@@ -264,20 +277,19 @@
-
+
+
@@ -301,25 +313,30 @@
-
-
+
+
-
-
-
+
+
+
+
-
-
-
+
+
+
+
-
-
-
+
+
+
+
-
-
-
+
+
+
+
-
+
+
\ No newline at end of file
diff --git a/src/App.js b/src/App.js
index c6836cd..55941da 100644
--- a/src/App.js
+++ b/src/App.js
@@ -7,7 +7,6 @@ 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 GithubState from './context/github/GithubState';
@@ -15,19 +14,6 @@ import './App.css';
const App = () => {
const [alert, setAlert] = useState(null);
- const [repos, setRepos] = useState([]);
-
- const getUserRepos = async username => {
- // setLoading(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}`
- );
-
- setRepos(res.data);
- // setLoading(false);
- };
// Show an alert
@@ -63,15 +49,7 @@ const App = () => {
(
-
- )}
+ component={User}
/>
diff --git a/src/components/users/User.js b/src/components/users/User.js
index 6200e48..2c23db9 100644
--- a/src/components/users/User.js
+++ b/src/components/users/User.js
@@ -5,9 +5,9 @@ import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import GithubContext from '../../context/github/githubContext';
-const User = ({ getUserRepos, repos, match }) => {
+const User = ({ match }) => {
const githubContext = useContext(GithubContext);
- const { getUser, loading, user } = githubContext;
+ const { getUser, loading, user, repos, getUserRepos } = githubContext;
useEffect(() => {
getUser(match.params.login);
@@ -104,9 +104,4 @@ const User = ({ getUserRepos, repos, match }) => {
);
};
-User.propTypes = {
- 'getUserRepos': PropTypes.func.isRequired,
- 'repos': PropTypes.array.isRequired
-};
-
export default User;
diff --git a/src/context/github/GithubState.js b/src/context/github/GithubState.js
index 9af2bb2..01b46a0 100644
--- a/src/context/github/GithubState.js
+++ b/src/context/github/GithubState.js
@@ -53,6 +53,20 @@ const GithubState = props => {
// get repos
+ const getUserRepos = async username => {
+ setLoading();
+ 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}`
+ );
+
+ dispatch({
+ 'type': GET_REPOS,
+ 'payload': res.data
+ });
+ };
+
/*
* clear users
* Clear Users from State
@@ -73,7 +87,8 @@ const GithubState = props => {
'loading': state.loading,
searchUsers,
clearUsers,
- getUser
+ getUser,
+ getUserRepos
}}
>
diff --git a/src/context/github/githubReducer.js b/src/context/github/githubReducer.js
index f88ff22..a956332 100644
--- a/src/context/github/githubReducer.js
+++ b/src/context/github/githubReducer.js
@@ -28,6 +28,12 @@ export default (state, action) => {
users:[],
loading:false
};
+ case GET_REPOS:
+ return {
+ ...state,
+ repos: action.payload,
+ loading: false
+ };
case SET_LOADING:
return {
...state,