From c6b5c21e44bbbda167c923132a4861a85dec90d2 Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Thu, 10 Oct 2019 16:24:04 +0100 Subject: [PATCH] End of chapter 29 --- .idea/workspace.xml | 18 +++++-- src/App.js | 81 +++++++++++++++-------------- src/context/github/GithubState.js | 45 ++++++++++++++++ src/context/github/githubContext.js | 5 ++ src/context/github/githubReducer.js | 0 src/context/types.js | 7 +++ 6 files changed, 115 insertions(+), 41 deletions(-) create mode 100644 src/context/github/GithubState.js create mode 100644 src/context/github/githubContext.js create mode 100644 src/context/github/githubReducer.js create mode 100644 src/context/types.js diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ef026e1..5bb90c0 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,6 +2,10 @@ + + + + @@ -116,7 +120,7 @@ - + 1569512995385 @@ -223,7 +227,14 @@ - @@ -258,6 +269,7 @@ - \ No newline at end of file diff --git a/src/App.js b/src/App.js index f79f301..47c3231 100644 --- a/src/App.js +++ b/src/App.js @@ -8,6 +8,9 @@ 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'; + import './App.css'; const App = () => { @@ -72,47 +75,49 @@ const App = () => { }; return ( - -
- + + +
+ -
- - - ( - - 0} - setAlert={showAlert} +
+ + + ( + + 0} + setAlert={showAlert} + /> + + + )} + /> + + ( + - - - )} - /> - - ( - - )} - /> - + )} + /> + +
-
-
+ +
); }; diff --git a/src/context/github/GithubState.js b/src/context/github/GithubState.js new file mode 100644 index 0000000..234bced --- /dev/null +++ b/src/context/github/GithubState.js @@ -0,0 +1,45 @@ +import React, { useReducer } from 'react'; +import axios from 'axios'; +import GithubContext from './githubContext'; +import GithubReducer from './githubReducer'; + +import { + SEARCH_USERS, CLEAR_USERS, GET_REPOS, GET_USER, REMOVE_ALERT, SET_ALERT, SET_LOADING + +} from '../types'; + +const GithubState = props => { + const initialState = { + 'users': [], + 'user': {}, + 'repos' : [], + 'loading': false + }; + + const [state, dispatch] = useReducer(GithubReducer, initialState); + + // search users + + // get user + + // get repos + + // clear users + + // set loading + + return + {props.children} + ; +}; + +export default GithubState; diff --git a/src/context/github/githubContext.js b/src/context/github/githubContext.js new file mode 100644 index 0000000..b4326b8 --- /dev/null +++ b/src/context/github/githubContext.js @@ -0,0 +1,5 @@ +import { createContext } from 'react'; + +const githubContext = createContext(); + +export default githubContext; diff --git a/src/context/github/githubReducer.js b/src/context/github/githubReducer.js new file mode 100644 index 0000000..e69de29 diff --git a/src/context/types.js b/src/context/types.js new file mode 100644 index 0000000..2c520de --- /dev/null +++ b/src/context/types.js @@ -0,0 +1,7 @@ +export const SEARCH_USERS = 'SEARCH_USERS'; +export const GET_USER = 'GET_USER'; +export const CLEAR_USERS = 'CLEAR_USERS'; +export const GET_REPOS = 'GET_REPOS'; +export const SET_LOADING = 'SET_LOADING'; +export const SET_ALERT = 'SET_ALERT'; +export const REMOVE_ALERT = 'REMOVE_ALERT';