-
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.
Merge pull request #3 from soma-miniproject22/test
add react router
- Loading branch information
Showing
15 changed files
with
373 additions
and
169 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { createContext, useState, useMemo } from 'react'; | ||
|
||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; | ||
|
||
import App from './App'; | ||
import AddPost from './pages/AddPost'; | ||
import Redirect from './pages/Redirect'; | ||
|
||
export const UserContext = createContext({ | ||
token: '', | ||
setToken: () => {}, | ||
}); | ||
|
||
const Routers = () => { | ||
const [token, setToken] = useState(''); | ||
|
||
const value = useMemo(() => ({ token, setToken }), [token, setToken]); | ||
|
||
return ( | ||
<UserContext.Provider value={value}> | ||
<Router> | ||
<Routes> | ||
<Route path="/" element={<App />} /> | ||
<Route path="/redirect" element={<Redirect />} /> | ||
<Route path="/addpost" element={<AddPost />} /> | ||
{/* <Route path="*" component={<404_page/>} /> */} | ||
</Routes> | ||
</Router> | ||
</UserContext.Provider> | ||
); | ||
}; | ||
|
||
export default Routers; |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import Interceptor from './Interceptor'; | ||
import CONFIG from './config'; | ||
|
||
class Api { | ||
/** | ||
* User Login | ||
* @param {string} redirect - url | ||
* @return {Object} response | ||
* @example | ||
* ``` json | ||
* { | ||
* "id": "UUID", | ||
* "dateTime": "datetime", | ||
* "success": true, | ||
* "response": "https://github.com/login/oauth/authorize?client_id=0c696e3a1df74b0acf03&redirect_uri=http://localhost:8080/api/oauth2/code/github?redirect=http://localhost:3000", | ||
* "error": null | ||
* } | ||
* ``` | ||
*/ | ||
async signin() { | ||
return await handlePromiseGet('/authenticate/github', { | ||
redirect: CONFIG.BASE_URL, | ||
}); | ||
} | ||
|
||
/** | ||
* get Information of Posts | ||
* @param {Date} required_date - required_date of cards | ||
* @return {Object} response | ||
* @example | ||
* ``` json | ||
* { | ||
* "dateTime": "datetime", | ||
* "success": true, | ||
* "response": [{ | ||
* "제목": "string", | ||
* "장소(optional)": "string", | ||
* "약속시간": "datetime", | ||
* "종류": "enum(밥|커피|술)", | ||
* "모집인원": "number", | ||
* "모집상태": "enum", | ||
* }], | ||
* "error": null | ||
* } | ||
* ``` | ||
*/ | ||
async getPosts(tags) { | ||
return await handlePromiseGet('/posts', tags ? { tag: tags } : {}); | ||
} | ||
|
||
async pushPost(info) { | ||
return await handlePromisePost('/posts', info); | ||
} | ||
|
||
async toggleEye() { | ||
return await handlePromiseGet('/toggleEye'); | ||
} | ||
|
||
async toggleHand() { | ||
return await handlePromiseGet('/toggleHand'); | ||
} | ||
|
||
// async addPost(post) { | ||
// return await handlePromisePost('/posts', post); | ||
// } | ||
} | ||
|
||
export default new Api(); | ||
|
||
/* | ||
{headers: authHeader()} | ||
Record<string, string> | ||
*/ | ||
function authHeader(token) { | ||
// eslint-disable-next-line no-unused-vars | ||
return token | ||
? { | ||
headers: { Authorization: token }, | ||
} | ||
: {}; | ||
} | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
const handlePromiseGet = async (url, params = {}) => { | ||
return new Promise((resolve, reject) => { | ||
Interceptor.getInstance() | ||
.get(CONFIG.API_SERVER + url, { params: params }) | ||
.then((res) => res.data) | ||
.then((res) => { | ||
if (!res.error) resolve(res.data); | ||
throw new Error(res.error); | ||
}) | ||
.catch((e) => reject(e)); | ||
}); | ||
}; | ||
|
||
const handlePromisePost = async (url, params = {}, token = '') => { | ||
return new Promise((resolve, reject) => { | ||
Interceptor.getInstance() | ||
.post(CONFIG.API_SERVER + url, params, authHeader(token)) | ||
.then((res) => res.data) | ||
.then((res) => { | ||
if (!res.error) resolve(res.data); | ||
throw new Error(res.error); | ||
}) | ||
.catch((e) => reject(e)); | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#add_post { | ||
position: fixed; | ||
font-size: 3em; | ||
right: 10px; | ||
bottom: 10px; | ||
cursor: pointer; | ||
} |
Oops, something went wrong.