-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
200 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,47 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import React, { useContext, useEffect, useState } from 'react'; | ||
import { RouterProvider } from 'react-router-dom'; | ||
import router from './routes/Route'; | ||
import GlobalStyles from './styles/GlobalStyle'; | ||
import { ThemeProvider } from 'styled-components'; | ||
import theme from './styles/ThemeStyle'; | ||
<<<<<<< HEAD | ||
import Header from './components/Header'; | ||
import Footer from './components/Footer'; | ||
function App() { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<GlobalStyles /> | ||
|
||
<RouterProvider router={router} /> | ||
======= | ||
import User from './pages/MyPage/User'; | ||
import Login from './apis/auth/Login'; | ||
import { UserProvider } from './apis/UserContext'; | ||
import MyPage from './pages/MyPage/MyPage'; | ||
import { UserProvider, UserContext } from './apis/UserContext'; | ||
|
||
function App() { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<UserProvider> | ||
<Login /> | ||
<UserProvider> | ||
<ThemeProvider theme={theme}> | ||
<Main /> | ||
<GlobalStyles /> | ||
<RouterProvider router={router} /> | ||
</UserProvider> | ||
>>>>>>> f92c3a333f9951f2d753eb2cda5ce545ce479d76 | ||
</ThemeProvider> | ||
</ThemeProvider> | ||
</UserProvider> | ||
); | ||
} | ||
|
||
const Main = () => { | ||
const { userId } = useContext(UserContext); | ||
const [ready, setReady] = useState(false); | ||
|
||
useEffect(() => { | ||
if (userId) { | ||
setReady(true); | ||
} | ||
}, [userId]); | ||
|
||
return ( | ||
<> | ||
<Login /> | ||
{ready && ( | ||
<> | ||
<User /> | ||
<MyPage /> | ||
</> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,64 @@ | ||
import React from 'react'; | ||
import UseApiRequest from './useapirequest'; | ||
// import React from 'react'; | ||
// import UseApiRequest from './useapirequest'; | ||
|
||
const MyComponent = () => { | ||
const { | ||
data: loginData, | ||
error: loginError, | ||
loading: loginLoading, | ||
} = UseApiRequest( | ||
'http://ec2-43-201-143-81.ap-northeast-2.compute.amazonaws.com:8080/login/github', | ||
'GET', | ||
); | ||
// const MyComponent = () => { | ||
// const { | ||
// data: loginData, | ||
// error: loginError, | ||
// loading: loginLoading, | ||
// } = UseApiRequest( | ||
// 'http://ec2-43-201-143-81.ap-northeast-2.compute.amazonaws.com:8080/login/github', | ||
// 'GET', | ||
// ); | ||
|
||
const { | ||
data: commitTestData, | ||
error: commitTestError, | ||
loading: commitTestLoading, | ||
} = UseApiRequest( | ||
'http://ec2-43-201-143-81.ap-northeast-2.compute.amazonaws.com:8080/commit/test/fetch', | ||
'POST', | ||
); | ||
// const { | ||
// data: commitTestData, | ||
// error: commitTestError, | ||
// loading: commitTestLoading, | ||
// } = UseApiRequest( | ||
// 'http://ec2-43-201-143-81.ap-northeast-2.compute.amazonaws.com:8080/commit/test/fetch', | ||
// 'POST', | ||
// ); | ||
|
||
const { | ||
data: commitData, | ||
error: commitError, | ||
loading: commitLoading, | ||
} = UseApiRequest( | ||
'http://ec2-43-201-143-81.ap-northeast-2.compute.amazonaws.com:8080/commit/fetch', | ||
'POST', | ||
); | ||
// const { | ||
// data: commitData, | ||
// error: commitError, | ||
// loading: commitLoading, | ||
// } = UseApiRequest( | ||
// 'http://ec2-43-201-143-81.ap-northeast-2.compute.amazonaws.com:8080/commit/fetch', | ||
// 'POST', | ||
// ); | ||
|
||
const { | ||
data: userData, | ||
error: userError, | ||
loading: userLoading, | ||
} = UseApiRequest( | ||
'http://ec2-43-201-143-81.ap-northeast-2.compute.amazonaws.com:8080/user/search?githubId=woneeeee', | ||
'GET', | ||
); | ||
// const { | ||
// data: userData, | ||
// error: userError, | ||
// loading: userLoading, | ||
// } = UseApiRequest( | ||
// 'http://ec2-43-201-143-81.ap-northeast-2.compute.amazonaws.com:8080/user/search?githubId=woneeeee', | ||
// 'GET', | ||
// ); | ||
|
||
return ( | ||
<div> | ||
{loginLoading && <p>Loading login...</p>} | ||
{loginError && <p>Login error: {loginError.message}</p>} | ||
{loginData && <p>Login data: {JSON.stringify(loginData)}</p>} | ||
// return ( | ||
// <div> | ||
// {loginLoading && <p>Loading login...</p>} | ||
// {loginError && <p>Login error: {loginError.message}</p>} | ||
// {loginData && <p>Login data: {JSON.stringify(loginData)}</p>} | ||
|
||
{commitTestLoading && <p>Loading commit test data...</p>} | ||
{commitTestError && <p>Commit test error: {commitTestError.message}</p>} | ||
{commitTestData && ( | ||
<p>Commit test data: {JSON.stringify(commitTestData)}</p> | ||
)} | ||
// {commitTestLoading && <p>Loading commit test data...</p>} | ||
// {commitTestError && <p>Commit test error: {commitTestError.message}</p>} | ||
// {commitTestData && ( | ||
// <p>Commit test data: {JSON.stringify(commitTestData)}</p> | ||
// )} | ||
|
||
{commitLoading && <p>Loading commit data...</p>} | ||
{commitError && <p>Commit error: {commitError.message}</p>} | ||
{commitData && <p>Commit data: {JSON.stringify(commitData)}</p>} | ||
// {commitLoading && <p>Loading commit data...</p>} | ||
// {commitError && <p>Commit error: {commitError.message}</p>} | ||
// {commitData && <p>Commit data: {JSON.stringify(commitData)}</p>} | ||
|
||
{userLoading && <p>Loading user data...</p>} | ||
{userError && <p>User error: {userError.message}</p>} | ||
{userData && <p>User data: {JSON.stringify(userData)}</p>} | ||
</div> | ||
); | ||
}; | ||
// {userLoading && <p>Loading user data...</p>} | ||
// {userError && <p>User error: {userError.message}</p>} | ||
// {userData && <p>User data: {JSON.stringify(userData)}</p>} | ||
// </div> | ||
// ); | ||
// }; | ||
|
||
export default MyComponent; | ||
// export default MyComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import { useState, useEffect } from 'react'; | ||
import axios from 'axios'; | ||
// import { useState, useEffect } from 'react'; | ||
// import axios from 'axios'; | ||
|
||
const UseApiRequest = (url, method, body = null) => { | ||
const [data, setData] = useState(null); | ||
const [error, setError] = useState(null); | ||
const [loading, setLoading] = useState(false); | ||
// const UseApiRequest = (url, method, body = null) => { | ||
// const [data, setData] = useState(null); | ||
// const [error, setError] = useState(null); | ||
// const [loading, setLoading] = useState(false); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
setLoading(true); | ||
setError(null); | ||
try { | ||
const response = await axios({ | ||
method, | ||
url, | ||
data: body, | ||
}); | ||
setData(response.data); | ||
} catch (err) { | ||
setError(err); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
// useEffect(() => { | ||
// const fetchData = async () => { | ||
// setLoading(true); | ||
// setError(null); | ||
// try { | ||
// const response = await axios({ | ||
// method, | ||
// url, | ||
// data: body, | ||
// }); | ||
// setData(response.data); | ||
// } catch (err) { | ||
// setError(err); | ||
// } finally { | ||
// setLoading(false); | ||
// } | ||
// }; | ||
|
||
fetchData(); | ||
}, [url, method, body]); | ||
// fetchData(); | ||
// }, [url, method, body]); | ||
|
||
return { data, error, loading }; | ||
}; | ||
// return { data, error, loading }; | ||
// }; | ||
|
||
export default UseApiRequest; | ||
// export default UseApiRequest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.