feat: improve mobile navigation with tap-to-reset and history filtering
This commit is contained in:
@@ -2,10 +2,10 @@ import React from 'react';
|
||||
import { useNavigate, useLocation } from 'react-router-dom';
|
||||
import { useEventContext } from '../../context/EventContext';
|
||||
import { NavKey } from '../components/BottomNav';
|
||||
import { resolveTabTarget } from '../lib/tabHistory';
|
||||
import { resolveTabTarget, resolveDefaultTarget } from '../lib/tabHistory';
|
||||
import { adminPath } from '../../constants';
|
||||
|
||||
export function useMobileNav(currentSlug?: string | null) {
|
||||
export function useMobileNav(currentSlug?: string | null, activeTab?: NavKey) {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const { activeEvent } = useEventContext();
|
||||
@@ -13,18 +13,16 @@ export function useMobileNav(currentSlug?: string | null) {
|
||||
|
||||
const go = React.useCallback(
|
||||
(key: NavKey) => {
|
||||
const target = resolveTabTarget(key, slug);
|
||||
|
||||
// Tap-to-reset: If we are already at the target, and it is the home tab,
|
||||
// and we are not at the dashboard root, then go to dashboard.
|
||||
if (key === 'home' && location.pathname === target && target !== adminPath('/mobile/dashboard')) {
|
||||
navigate(adminPath('/mobile/dashboard'));
|
||||
// Tap-to-reset: If the user taps the tab they are already on, reset to root.
|
||||
if (key === activeTab) {
|
||||
navigate(resolveDefaultTarget(key, slug));
|
||||
return;
|
||||
}
|
||||
|
||||
const target = resolveTabTarget(key, slug);
|
||||
navigate(target);
|
||||
},
|
||||
[navigate, location.pathname, slug]
|
||||
[navigate, activeTab, slug]
|
||||
);
|
||||
|
||||
return { go, slug };
|
||||
|
||||
Reference in New Issue
Block a user