From 95ac4832bde4eb8a8acc1d588cb42562817e1367 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sun, 9 Mar 2025 15:51:51 +0100 Subject: [PATCH] Fix "main route" detection There was a possibility that routes were incorrectly detected as main routes which caused the back button to not get shown. E.g. a route that is only visible on desktop was still considered a main route on mobile devices --- .../components/DefaultNavBar.tsx | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/modules/navigation-bar/components/DefaultNavBar.tsx b/src/modules/navigation-bar/components/DefaultNavBar.tsx index 002ee9a7..ae7dd84c 100644 --- a/src/modules/navigation-bar/components/DefaultNavBar.tsx +++ b/src/modules/navigation-bar/components/DefaultNavBar.tsx @@ -82,11 +82,7 @@ export function DefaultNavBar() { const getOptionForDirection = useGetOptionForDirection(); const { pathname } = useLocation(); const handleBack = useBackButton(); - const isMobileWidth = MediaQuery.useIsMobileWidth(); - const isMainRoute = navbarItems.some(({ path }) => path === pathname); - - const actualNavBarWidth = isMobileWidth || isCollapsed ? 0 : navBarWidth; const appBarRef = useRef(null); useResizeObserver( @@ -103,6 +99,19 @@ export function DefaultNavBar() { return () => setAppBarHeight(0); }, [override.status]); + const isMainRoute = navbarItems.some(({ path, show }) => { + if (isMobileWidth && show === 'desktop') { + return false; + } + + if (!isMobileWidth && show === 'mobile') { + return false; + } + + return path === pathname; + }); + const actualNavBarWidth = isMobileWidth || isCollapsed ? 0 : navBarWidth; + const activeNavBar: NavbarItem['show'] = isMobileWidth ? 'mobile' : 'desktop'; const visibleNavBarItems = useMemo( () => navbarItems.filter(({ show }) => ['both', activeNavBar].includes(show)), @@ -110,6 +119,11 @@ export function DefaultNavBar() { ); const NavBarComponent = useMemo(() => (isMobileWidth ? MobileBottomBar : DesktopSideBar), [isMobileWidth]); + const navBar = useMemo( + () => , + [NavBarComponent, visibleNavBarItems], + ); + useLayoutEffect(() => { if (!isMobileWidth) { // do not reset navbar width to prevent grid from jumping due to the changing grid item width @@ -119,11 +133,6 @@ export function DefaultNavBar() { setNavBarWidth(0); }, [isMobileWidth]); - const navBar = useMemo( - () => , - [NavBarComponent, visibleNavBarItems], - ); - // Allow default navbar to be overrided if (override.status) return override.value;