Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

1.6 KB
Raw Blame
import { useLocation, useMatch, useNavigate } from 'react-router';
import { useNavItems } from '../../components/Layout/navItems';
import { useCreateAction } from '../../components/Layout/useCreateAction';
import { useTranslation } from '../../i18n';
import type { Shortcut } from './shortcuts';
import { useShortcuts } from './useShortcuts';

/**
 * The app-wide shortcuts of the touch shell: ⌘1 to ⌘9 for the sections in the
 * order the rail shows them, ⌘N for what the "+" creates here, ⌘, for
 * settings. Inside a trip the numbers and ⌘N belong to the trip (MTripShell):
 * its tabs change without a new URL, and this component renders only on one,
 * so a ⌘N of its own would still create what the tab the trip opened on does.
 */
export default function MShellShortcuts() {
  const { t } = useTranslation();
  const navigate = useNavigate();
  const location = useLocation();
  const inTrip = useMatch('/trips/:id');
  const navItems = useNavItems();
  const create = useCreateAction(true);
  const noCreate = ['/settings', '/admin', '/vacay'].some((p) => location.pathname.startsWith(p));

  const shortcuts: Shortcut[] = [
    ...(inTrip
      ? []
      : navItems.slice(0, 9).map((item, i) => ({
          id: `go-${item.id}`,
          title: item.label,
          key: String(i + 1),
          mod: true,
          run: () => void navigate(item.to),
        }))),
    ...(noCreate || inTrip ? [] : [{ id: 'create', title: create.label, key: 'n', mod: true, run: create.run }]),
    { id: 'settings', title: t('nav.bottomSettings'), key: ',', mod: true, run: () => void navigate('/settings') },
  ];
  useShortcuts('shell', shortcuts);
  return null;
}