feat: improve mobile navigation with tap-to-reset and history filtering

This commit is contained in:
Codex Agent
2026-01-07 15:14:31 +01:00
parent 8e1031fff0
commit 5866a0826c
3 changed files with 40 additions and 22 deletions

View File

@@ -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 };