Reset app bar height to 0 on unmount
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useCallback, useContext, useMemo, useRef } from 'react';
|
import { useCallback, useContext, useEffect, useMemo, useRef } from 'react';
|
||||||
import AppBar from '@mui/material/AppBar';
|
import AppBar from '@mui/material/AppBar';
|
||||||
import Toolbar from '@mui/material/Toolbar';
|
import Toolbar from '@mui/material/Toolbar';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
@@ -89,6 +89,7 @@ export function DefaultNavBar() {
|
|||||||
appBarRef,
|
appBarRef,
|
||||||
useCallback(() => setAppBarHeight(appBarRef.current?.clientHeight ?? 0), [appBarRef]),
|
useCallback(() => setAppBarHeight(appBarRef.current?.clientHeight ?? 0), [appBarRef]),
|
||||||
);
|
);
|
||||||
|
useEffect(() => setAppBarHeight(0), []);
|
||||||
|
|
||||||
const activeNavBar: NavbarItem['show'] = isMobileWidth ? 'mobile' : 'desktop';
|
const activeNavBar: NavbarItem['show'] = isMobileWidth ? 'mobile' : 'desktop';
|
||||||
const visibleNavBarItems = useMemo(
|
const visibleNavBarItems = useMemo(
|
||||||
|
|||||||
@@ -87,13 +87,12 @@ const MAX_WIDTH_EXTENDED = 400;
|
|||||||
export const DesktopSideBar = ({ navBarItems }: { navBarItems: NavbarItem[] }) => {
|
export const DesktopSideBar = ({ navBarItems }: { navBarItems: NavbarItem[] }) => {
|
||||||
const { isCollapsed, setIsCollapsed, navBarWidth, setNavBarWidth } = useNavBarContext();
|
const { isCollapsed, setIsCollapsed, navBarWidth, setNavBarWidth } = useNavBarContext();
|
||||||
|
|
||||||
useEffect(() => () => setNavBarWidth(0), []);
|
|
||||||
|
|
||||||
const ref = useRef<HTMLDivElement | null>(null);
|
const ref = useRef<HTMLDivElement | null>(null);
|
||||||
useResizeObserver(
|
useResizeObserver(
|
||||||
ref,
|
ref,
|
||||||
useCallback(() => setNavBarWidth(ref.current?.clientWidth ?? 0), [ref]),
|
useCallback(() => setNavBarWidth(ref.current?.clientWidth ?? 0), [ref]),
|
||||||
);
|
);
|
||||||
|
useEffect(() => () => setNavBarWidth(0), []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Drawer variant="permanent" sx={{ width: navBarWidth }}>
|
<Drawer variant="permanent" sx={{ width: navBarWidth }}>
|
||||||
|
|||||||
@@ -22,13 +22,12 @@ export const MobileBottomBar = ({ navBarItems }: { navBarItems: NavbarItem[] })
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
useEffect(() => () => setBottomBarHeight(0), []);
|
|
||||||
|
|
||||||
const ref = useRef<HTMLDivElement | null>(null);
|
const ref = useRef<HTMLDivElement | null>(null);
|
||||||
useResizeObserver(
|
useResizeObserver(
|
||||||
ref,
|
ref,
|
||||||
useCallback(() => setBottomBarHeight(ref.current?.clientHeight ?? 0), [ref]),
|
useCallback(() => setBottomBarHeight(ref.current?.clientHeight ?? 0), [ref]),
|
||||||
);
|
);
|
||||||
|
useEffect(() => () => setBottomBarHeight(0), []);
|
||||||
|
|
||||||
const [selectedNavBarItem, setSelectedNavBarItem] = useState(
|
const [selectedNavBarItem, setSelectedNavBarItem] = useState(
|
||||||
navBarItems.find((navBarItem) => navBarItem.path === location.pathname)?.path,
|
navBarItems.find((navBarItem) => navBarItem.path === location.pathname)?.path,
|
||||||
|
|||||||
Reference in New Issue
Block a user