import { useEffect, useState } from 'react' import { useNavigate, useLocation, useMatch } from 'react-router' import { useSettingsStore } from '../../store/settingsStore' import { useTranslation } from '../../i18n' import { ChevronRight, MoreHorizontal, Plus, Search } from 'lucide-react' import type { LucideIcon } from 'lucide-react' import { normalizeAppearance } from '@trek/shared' import { useNavItems, splitMobileNav } from '../../components/Layout/navItems' import MFab from './MFab' interface NavItem { to: string; label: string; icon: LucideIcon } // The centre "+" means something different per context: inside a trip it adds a // place, on the journey list it starts a journey (deliberate deviation from the // demo, which reserves the FAB for entries — the list has no journey to add // into yet), inside a journey it adds an entry, on the atlas it opens the // country search, on collections it adds a place to the active list — // everywhere else it creates a new trip. Pages pick the intent up from the // query params. The result is unused on /vacay: that screen draws its own centre // FAB, so the dock yields the slot instead (see screenFabSlot below, #1811). function useCreateAction(): { label: string; run: () => void } { const navigate = useNavigate() const { t } = useTranslation() const inTrip = useMatch('/trips/:id') const inJourney = useMatch('/journey/:id') const onJourneyList = useMatch('/journey') const onAtlas = useMatch('/atlas') const onCollections = useMatch('/collections') const inCollection = useMatch('/collections/:id') if (inTrip) { // The "+" is context-aware per active tab: Bookings → reservation, // Transports → transport, Costs → expense. Tabs without a create modal // (lists / files / collab) fall through to adding a place. #1349 const id = inTrip.params.id const tripTab = typeof sessionStorage !== 'undefined' ? sessionStorage.getItem(`trip-tab-${id}`) : null if (tripTab === 'finanzplan') return { label: t('costs.addExpense'), run: () => navigate(`/trips/${id}?create=expense`) } if (tripTab === 'buchungen') return { label: t('reservations.addManual'), run: () => navigate(`/trips/${id}?create=reservation`) } if (tripTab === 'transports') return { label: t('transport.addManual'), run: () => navigate(`/trips/${id}?create=transport`) } return { label: t('places.addPlace'), run: () => navigate(`/trips/${id}?create=place`) } } if (inJourney) { return { label: t('journey.detail.addEntry'), run: () => navigate(`/journey/${inJourney.params.id}?create=entry`) } } if (onJourneyList) { return { label: t('journey.new'), run: () => navigate('/journey?create=1') } } if (onAtlas) { return { label: t('atlas.searchCountry'), run: () => navigate('/atlas?search=1') } } if (onCollections || inCollection) { // Picking a list moves the route to /collections/:id, so the exact match // alone dropped the "+" through to creating a trip — the one state the // screen is normally used in (#1930). The handoff keeps the id, otherwise // adding would land on "All saved" and the sheet would ask for the list the // user is already looking at. const path = inCollection ? `/collections/${inCollection.params.id}` : '/collections' return { label: t('collections.addPlace'), run: () => navigate(`${path}?create=place`) } } return { label: t('dashboard.newTrip'), run: () => navigate('/dashboard?create=1') } } /** * Floating glass dock of the mobile shell. Same tab/gating/"+" logic as the * legacy BottomNav (addons, ?create= contract), redesigned as the demo's icon * dock: 42px circles, active on the --m-act pill, Journey/Collections and page * plugins behind the "More" popover, and a context FAB in the middle (search * on the atlas, disabled logo slot on settings/admin). */ export default function MBottomNav() { const { t } = useTranslation() const navigate = useNavigate() const location = useLocation() const create = useCreateAction() const [moreOpen, setMoreOpen] = useState(false) // Close the popover when the route changes underneath it (browser back etc.). useEffect(() => setMoreOpen(false), [location.pathname]) // The dock split + order is user-configurable (Settings → Appearance → Mobile); // an un-customised account falls back to the built-in Dashboard + vacay/atlas // dock with everything else under "More". const navItems = useNavItems() const appearance = useSettingsStore(s => s.settings.appearance) const split = splitMobileNav(navItems, normalizeAppearance(appearance).mobileNav) const dockItems: NavItem[] = split.bar const moreItems: NavItem[] = split.more const isActive = (to: string) => to === '/dashboard' ? location.pathname === '/dashboard' : location.pathname.startsWith(to) const moreActive = moreItems.some(item => isActive(item.to)) // The FAB gives way to a decorative logo slot on screens without an add // action (settings/admin, demo Z. 1372/1429). const logoSlot = location.pathname.startsWith('/settings') || location.pathname.startsWith('/admin') const searchFab = location.pathname.startsWith('/atlas') // /vacay owns the centre slot itself: MVacay draws its year/edit toggle into // exactly this 56px circle. The dock keeps the geometry but stays empty there, // so the generic "+" can never sit underneath as a second, different action: // not while the lazy screen chunk loads, and not while its data loads (#1811). const screenFabSlot = location.pathname.startsWith('/vacay') // Split so the raised centre slot sits dead centre; the More slot always // closes the right group. const slotCount = dockItems.length + (moreItems.length > 0 ? 1 : 0) const splitAt = Math.ceil(slotCount / 2) const left = dockItems.slice(0, splitAt) const right = dockItems.slice(splitAt) const circleCls = (active: boolean) => `flex h-[42px] w-[42px] flex-none items-center justify-center rounded-full ${ active ? 'bg-m-act text-m-actfg' : 'text-m-muted' }` const renderItem = ({ to, label, icon: Icon }: NavItem) => { const active = isActive(to) // Fixed sizes per slot (demo): the dashboard grid is 18/2.1, every other // slot 21/1.9 — independent of the active state. const dash = to === '/dashboard' return ( ) } return ( <> {moreOpen && ( // Invisible scrim (the popover sits on the UI without dimming it).
setMoreOpen(false)}>
e.stopPropagation()} > {moreItems.map(({ to, label, icon: Icon }) => ( ))}
)} ) }