fix: resolve typescript and build errors across admin and guest apps
This commit is contained in:
@@ -1,20 +1,30 @@
|
||||
import React from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
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, slug]
|
||||
[navigate, location.pathname, slug]
|
||||
);
|
||||
|
||||
return { go, slug };
|
||||
|
||||
Reference in New Issue
Block a user