-
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
1 parent
2900f50
commit e7c4644
Showing
10 changed files
with
185 additions
and
38 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,52 @@ | ||
/* eslint-disable prettier/prettier */ | ||
/* eslint-disable no-unused-vars */ | ||
import React, { | ||
createContext, | ||
useState, | ||
useMemo, | ||
} from 'react'; | ||
|
||
import { | ||
BrowserRouter as Router, | ||
Routes, | ||
Route, | ||
} from 'react-router-dom'; | ||
|
||
import App from './App'; | ||
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="/about" component={About} /> | ||
<Route path="/login" component={Login} /> | ||
<Route path="/register" component={Register} /> | ||
<Route path="/profile" component={Profile} /> | ||
<Route path="/add-post" component={AddPost} /> | ||
<Route path="/edit-post/:id" component={EditPost} /> | ||
<Route path="/post/:id" component={Post} /> | ||
<Route path="/posts" component={Posts} /> | ||
<Route path="/users" component={Users} /> | ||
<Route path="/user/:id" component={User} /> | ||
<Route path="/search" component={Search} /> */} | ||
{/* <Route path="*" component={404_page} /> */} | ||
</Routes> | ||
</Router> | ||
</UserContext.Provider> | ||
); | ||
}; | ||
|
||
export default Routers; |
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,7 @@ | ||
#add_post { | ||
position: fixed; | ||
font-size: 3em; | ||
right: 10px; | ||
bottom: 10px; | ||
cursor: pointer; | ||
} |
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,15 @@ | ||
import React from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import './index.css'; | ||
|
||
const AddPost = () => { | ||
const navigate = useNavigate(); | ||
|
||
const handleClick = () => { | ||
return navigate('/add-post'); | ||
}; | ||
|
||
return <i className="plus circle icon" id="add_post" onClick={handleClick} />; | ||
}; | ||
|
||
export default AddPost; |
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,16 @@ | ||
/* eslint-disable no-unused-vars */ | ||
import React, { useContext } from 'react'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
import { UserContext } from '../Routers'; | ||
|
||
function Redirect() { | ||
const [searchParams, setSearchParams] = useSearchParams(); | ||
const { token, setToken } = useContext(UserContext); | ||
|
||
if (searchParams.get('access_token')) | ||
setToken(searchParams.get('access_token')); | ||
|
||
return <div />; | ||
} | ||
|
||
export default Redirect; |