Files
fotospiel-app/resources/js/admin/mobile/hooks/useMobileNav.ts
Codex Agent 22cb7ed7ce
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
fix: resolve typescript and build errors across admin and guest apps
2026-01-07 13:25:30 +01:00

32 lines
1.0 KiB
TypeScript

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 { adminPath } from '../../constants';
export function useMobileNav(currentSlug?: string | null) {
const navigate = useNavigate();
const location = useLocation();
const { activeEvent } = useEventContext();
const slug = currentSlug ?? activeEvent?.slug ?? 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'));
return;
}
navigate(target);
},
[navigate, location.pathname, slug]
);
return { go, slug };
}