-
Notifications
You must be signed in to change notification settings - Fork 412
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
24 changed files
with
107 additions
and
117 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,44 +1,44 @@ | ||
import { changeIsLogged } from './redux/Reducers/isLogged'; | ||
import { changeIsLogged } from './context/redux/Reducers/isLogged'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { SocketContext, socket } from './Context'; | ||
import { SocketContext, socket } from './context/Context'; | ||
|
||
// Components | ||
import Login from './components/Login/Login'; | ||
import RoutesComponent from './components/Routes'; | ||
import Login from './pages/Login/Login'; | ||
import RoutesComponent from './components/Navigation/Routes'; | ||
import { useEffect } from 'react'; | ||
|
||
function App() { | ||
const dispatch = useDispatch(); | ||
const isLogged = useSelector((state) => state.isLogged); | ||
const isUserLoggedIn = useSelector((state) => { | ||
const { isLogged } = state; | ||
const dispatch = useDispatch(); | ||
const isLogged = useSelector((state) => state.isLogged); | ||
const isUserLoggedIn = useSelector((state) => { | ||
const { isLogged } = state; | ||
|
||
return isLogged.isLoggedIn && isLogged.loginId !== null; | ||
}); | ||
return isLogged.isLoggedIn && isLogged.loginId !== null; | ||
}); | ||
|
||
useEffect(() => { | ||
// We need to convert the JSON string we saved to localStorage | ||
// back to the original state object first before dispatching | ||
// NOTE: Using try...catch here to prevent blank page on first visit | ||
// (previous issue that was solved) | ||
try { | ||
dispatch(changeIsLogged(JSON.parse(window.localStorage.isLogged))); | ||
} catch { | ||
dispatch(changeIsLogged({})); | ||
} | ||
}, []); | ||
useEffect(() => { | ||
// We need to convert the JSON string we saved to localStorage | ||
// back to the original state object first before dispatching | ||
// NOTE: Using try...catch here to prevent blank page on first visit | ||
// (previous issue that was solved) | ||
try { | ||
dispatch(changeIsLogged(JSON.parse(window.localStorage.isLogged))); | ||
} catch { | ||
dispatch(changeIsLogged({})); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
// `localStorage` only accepts strings so have to convert the state to | ||
// JSON format first | ||
window.localStorage.setItem('isLogged', JSON.stringify(isLogged)); | ||
}, [isLogged]); | ||
useEffect(() => { | ||
// `localStorage` only accepts strings so have to convert the state to | ||
// JSON format first | ||
window.localStorage.setItem('isLogged', JSON.stringify(isLogged)); | ||
}, [isLogged]); | ||
|
||
return ( | ||
<SocketContext.Provider value={socket}> | ||
<div>{isUserLoggedIn ? <RoutesComponent /> : <Login />}</div> | ||
</SocketContext.Provider> | ||
); | ||
return ( | ||
<SocketContext.Provider value={socket}> | ||
<div>{isUserLoggedIn ? <RoutesComponent /> : <Login />}</div> | ||
</SocketContext.Provider> | ||
); | ||
} | ||
|
||
export default App; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { NavLink } from 'react-router-dom'; | ||
// Icons | ||
|
||
import { BsChatDots } from 'react-icons/bs'; | ||
import { RiUserSearchLine } from 'react-icons/ri'; | ||
import { BiUserCircle } from 'react-icons/bi'; | ||
|
||
const linkStyle = `h-[80px] w-[100%] flex items-center justify-center hover:bg-primary p-6 rounded-[15px] `; | ||
const activeStyle = linkStyle + 'bg-primary shadow-2xl'; | ||
const iconStyle = 'fill-[#f5f5f5] scale-[2]'; | ||
|
||
const NavBar = () => { | ||
|
||
|
||
|
||
return ( | ||
<div | ||
className=" | ||
navContainer bg-secondary | ||
w-[120px] min-h-[100vh] | ||
flex items-center flex-col | ||
justify-center shadow-[0_0_100px_0_rgba(0,0,0,1)] p-5" | ||
> | ||
<div className="justify-between flex items-center flex-col h-[35%] w-[100%]"> | ||
<NavLink | ||
to="/" | ||
className={({ isActive }) => | ||
(isActive ? activeStyle : linkStyle) | ||
} | ||
> | ||
<RiUserSearchLine className={iconStyle} /> | ||
</NavLink> | ||
<NavLink | ||
to="/friends" | ||
className={({ isActive }) => | ||
(isActive ? activeStyle : linkStyle) | ||
} | ||
> | ||
<BsChatDots className={iconStyle} /> | ||
</NavLink> | ||
<NavLink | ||
to="/profile" | ||
className={({ isActive }) => | ||
(isActive ? activeStyle : linkStyle) | ||
} | ||
> | ||
<BiUserCircle className={iconStyle} /> | ||
</NavLink> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NavBar; |
12 changes: 6 additions & 6 deletions
12
client/src/components/Routes.jsx → client/src/components/Navigation/Routes.jsx
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 was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
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