Skip to content

Commit

Permalink
Merge pull request #273 from UofA-Blueprint/fix/sidebarAutoClose
Browse files Browse the repository at this point in the history
Auto close sidebar
  • Loading branch information
royayush1 authored Dec 16, 2023
2 parents dc335b3 + fe3e63a commit dbcf28b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions app/src/widgets/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ export const Sidebar = () => {
const { currentUser, logout } = useAuth();
const [admin, setAdmin] = useState(false);
const [volunteer, setVolunteer] = useState(false);
const [isSidebarOpen, setIsSidebarOpen] = useState(false);

const closeSidebar = () => {
setIsSidebarOpen(false);
};

// Sync state with the opening/closing of the sidebar
const handleSidebarStateChange = (state) => {
setIsSidebarOpen(state.isOpen);
};

//When we load the page or refresh, check the role of the user and setadmin or volunteer accordingly
useEffect(() => {
Expand All @@ -29,10 +39,8 @@ export const Sidebar = () => {
}
}, [currentUser]);



return (
<Menu>
<Menu isOpen={isSidebarOpen} onStateChange={handleSidebarStateChange}>
<p
className="memu-title"
style={{
Expand All @@ -44,7 +52,7 @@ export const Sidebar = () => {
</p>

<p>MENU</p>
<ReactRouterLink className="menu-item" to="/home">
<ReactRouterLink className="menu-item" to="/home" onClick={closeSidebar}>
<img style={{ paddingRight: 16 }} src={home_icon} alt="" />
Home
</ReactRouterLink>
Expand All @@ -60,6 +68,7 @@ export const Sidebar = () => {
className="menu-item"
to="/volunteer/return"
style={{ paddingTop: 10 }}
onClick={closeSidebar}
>
<img style={{ paddingRight: 16 }} src={task_icon} alt="" />
Return Dishes
Expand Down

0 comments on commit dbcf28b

Please sign in to comment.