End of chapter 29
This commit is contained in:
parent
72c3a69812
commit
c6b5c21e44
@ -2,6 +2,10 @@
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="5be46653-49b7-409a-9549-21ca1be137cc" name="Default Changelist" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/src/context/github/GithubState.js" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/context/github/githubContext.js" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/context/github/githubReducer.js" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/context/types.js" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/App.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/App.js" afterDir="false" />
|
||||
</list>
|
||||
@ -116,7 +120,7 @@
|
||||
<workItem from="1570713697039" duration="68000" />
|
||||
<workItem from="1570713775683" duration="2307000" />
|
||||
<workItem from="1570716281021" duration="2536000" />
|
||||
<workItem from="1570719196036" duration="307000" />
|
||||
<workItem from="1570719196036" duration="1629000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="End of Chapter 14">
|
||||
<created>1569512995385</created>
|
||||
@ -223,7 +227,14 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1570718032804</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="16" />
|
||||
<task id="LOCAL-00016" summary="End of chapter 28">
|
||||
<created>1570719686766</created>
|
||||
<option name="number" value="00016" />
|
||||
<option name="presentableId" value="LOCAL-00016" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1570719686766</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="17" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@ -258,6 +269,7 @@
|
||||
<MESSAGE value="End of chapter 24" />
|
||||
<MESSAGE value="End of chapter 26" />
|
||||
<MESSAGE value="End of chapter 27" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="End of chapter 27" />
|
||||
<MESSAGE value="End of chapter 28" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="End of chapter 28" />
|
||||
</component>
|
||||
</project>
|
81
src/App.js
81
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 (
|
||||
<Router>
|
||||
<div className="App">
|
||||
<Navbar title="Github Finder" icon="fab fa-github" />
|
||||
<GithubState>
|
||||
<Router>
|
||||
<div className="App">
|
||||
<Navbar title="Github Finder" icon="fab fa-github" />
|
||||
|
||||
<div className="container">
|
||||
<Alert alert={alert} />
|
||||
<Switch>
|
||||
<Route
|
||||
exact
|
||||
path="/"
|
||||
render={props => (
|
||||
<Fragment>
|
||||
<Search
|
||||
searchUsers={searchUsers}
|
||||
clearUsers={clearUsers}
|
||||
showClear={users.length > 0}
|
||||
setAlert={showAlert}
|
||||
<div className="container">
|
||||
<Alert alert={alert} />
|
||||
<Switch>
|
||||
<Route
|
||||
exact
|
||||
path="/"
|
||||
render={props => (
|
||||
<Fragment>
|
||||
<Search
|
||||
searchUsers={searchUsers}
|
||||
clearUsers={clearUsers}
|
||||
showClear={users.length > 0}
|
||||
setAlert={showAlert}
|
||||
/>
|
||||
<Users loading={loading} users={users} />
|
||||
</Fragment>
|
||||
)}
|
||||
/>
|
||||
<Route exact path="/about" component={About} />
|
||||
<Route
|
||||
exact
|
||||
path="/user/:login"
|
||||
render={props => (
|
||||
<User
|
||||
{...props}
|
||||
getUser={getUser}
|
||||
getUserRepos={getUserRepos}
|
||||
user={user}
|
||||
loading={loading}
|
||||
repos={repos}
|
||||
/>
|
||||
<Users loading={loading} users={users} />
|
||||
</Fragment>
|
||||
)}
|
||||
/>
|
||||
<Route exact path="/about" component={About} />
|
||||
<Route
|
||||
exact
|
||||
path="/user/:login"
|
||||
render={props => (
|
||||
<User
|
||||
{...props}
|
||||
getUser={getUser}
|
||||
getUserRepos={getUserRepos}
|
||||
user={user}
|
||||
loading={loading}
|
||||
repos={repos}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</Switch>
|
||||
)}
|
||||
/>
|
||||
</Switch>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Router>
|
||||
</Router>
|
||||
</GithubState>
|
||||
);
|
||||
};
|
||||
|
||||
|
45
src/context/github/GithubState.js
Normal file
45
src/context/github/GithubState.js
Normal file
@ -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 <GithubContext.Provider
|
||||
|
||||
value={{
|
||||
'users': state.users,
|
||||
'user': state.user,
|
||||
'repos': state.repos,
|
||||
'loading': state.loading
|
||||
}}
|
||||
|
||||
>
|
||||
{props.children}
|
||||
</GithubContext.Provider>;
|
||||
};
|
||||
|
||||
export default GithubState;
|
5
src/context/github/githubContext.js
Normal file
5
src/context/github/githubContext.js
Normal file
@ -0,0 +1,5 @@
|
||||
import { createContext } from 'react';
|
||||
|
||||
const githubContext = createContext();
|
||||
|
||||
export default githubContext;
|
0
src/context/github/githubReducer.js
Normal file
0
src/context/github/githubReducer.js
Normal file
7
src/context/types.js
Normal file
7
src/context/types.js
Normal file
@ -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';
|
Loading…
Reference in New Issue
Block a user