Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Issue Number - 708 Fixed :- Added conditional logic to render Sign Out button for Logged In Users only #811

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/Components/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function Menu() {
const [sidebarOpen, setSidebarOpen] = useState(false);
const [isMobile, setIsMobile] = useState(window.innerWidth < 524);
const [showStopwatch, setShowStopwatch] = useState(false); // State to handle stopwatch visibility
const [isUserLoggedIn, setIsUserLoggedIn] = useState(localStorage.getItem('user') ? true : false);

useEffect(() => {
const handleResize = () => {
Expand All @@ -30,10 +31,12 @@ function Menu() {

window.addEventListener("resize", handleResize);

const user = localStorage.getItem('user');
setIsUserLoggedIn(user ? true : false);
return () => {
window.removeEventListener("resize", handleResize);
};
}, []);
}, [isUserLoggedIn]);

const toggleSidebar = () => {
setSidebarOpen(!sidebarOpen);
Expand All @@ -44,10 +47,8 @@ function Menu() {
};

const handleSignOut = () => {
console.log("User signed out");
setTimeout(() => {
// Handle any additional sign-out logic here
}, 3000);
localStorage.removeItem('user');
setIsUserLoggedIn(false);
};

const { theme } = useContext(ThemeContext)
Expand Down Expand Up @@ -122,12 +123,14 @@ function Menu() {
<span className="tooltip" style={{ marginLeft: '10px', fontSize: '1.1rem', color: 'white' }}>Settings</span>
</Link>
</li>
<li style={{ padding: '1rem', display: 'flex', alignItems: 'center', gap: '10px' }}>
{isUserLoggedIn && (
<li style={{ padding: '1rem', display: 'flex', alignItems: 'center', gap: '10px' }}>
<Link to="/" style={{ color: 'white', textDecoration: 'none', display: 'flex', alignItems: 'center' }}>
<FaSignOutAlt size={30} />
<span className="tooltip" style={{ marginLeft: '10px', fontSize: '1.1rem', color: 'white' }}>Sign Out</span>
<span className="tooltip" style={{ marginLeft: '10px', fontSize: '1.1rem', color: 'white' }} onClick={handleSignOut}>SignOut</span>
</Link>
</li>
)}
</ul>
</div>

Expand Down