diff --git a/frontend/src/components/Navbar.jsx b/frontend/src/components/Navbar.jsx index aeb710e..d3a7856 100644 --- a/frontend/src/components/Navbar.jsx +++ b/frontend/src/components/Navbar.jsx @@ -1,6 +1,7 @@ +import { useState, useEffect } from "react"; import { Link } from "react-router-dom"; -import { PlusIcon, Sun, Moon, LogOut } from "lucide-react"; +import { PlusIcon, Sun, Moon, LogOut, X } from "lucide-react"; import { useAuth } from "../context/AuthContext"; import { useTheme } from "../context/ThemeContext"; @@ -8,13 +9,32 @@ const Navbar = () => { const { user, logout } = useAuth(); const { theme, toggleTheme } = useTheme(); + const [showLogoutConfirm, setShowLogoutConfirm] = useState(false); + + const closeLogoutConfirm = () => setShowLogoutConfirm(false); + + const handleConfirmLogout = () => { + setShowLogoutConfirm(false); + logout(); + }; + + // Dismiss the confirmation modal with the Esc key while it is open. + useEffect(() => { + if (!showLogoutConfirm) return; + const handleKeyDown = (e) => { + if (e.key === "Escape") setShowLogoutConfirm(false); + }; + window.addEventListener("keydown", handleKeyDown); + return () => window.removeEventListener("keydown", handleKeyDown); + }, [showLogoutConfirm]); + return (
{/* Logo */} - ThinkBoard @@ -34,15 +54,15 @@ const Navbar = () => { {/* Auth Buttons */} {user ? (
- New Note
) : (
- Login - Sign Up @@ -68,8 +88,60 @@ const Navbar = () => {
+ + {/* Logout Confirmation Modal */} + {showLogoutConfirm && ( +
+
e.stopPropagation()} + > + {/* Close Button */} + + +

+ Log out? +

+

+ Are you sure you want to log out? You'll need to log back in to + access your notes. +

+ +
+ + +
+
+
+ )}
); }; -export default Navbar; \ No newline at end of file +export default Navbar;