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.

4.1 KB
Raw Blame
import type { MTripTabPanelProps } from '../MTripShell'
import { lazyWithRetry } from '../../../../utils/lazyWithRetry'
import { LazyPanel } from '../../../../pages/tripPlanner/LazyPanel'
import { TabScroller } from './tabChrome'
import MTransportsTab from './MTransportsTab'
import MBookingsTab from './MBookingsTab'
import MCostsTab from './MCostsTab'
import MFilesTab from './MFilesTab'
import MCollabTab from './MCollabTab'
import MListsTab from './MListsTab'
import MRoadtripTab from '../roadtrip/MRoadtripTab'
import MJourneyDetail from '../../journey/MJourneyDetail'
import PluginFrame from '../../../../components/Plugins/PluginFrame'

// The desktop's tour editor, map stage included: loaded the first time a large screen opens the tab.
const MTourWorkspace = lazyWithRetry(() => import('../tours/MTourWorkspace'))

/**
 * Routes the active non-plan trip tab to its panel. `tab` is the legacy id the
 * desktop planner uses (transports · buchungen · finanzplan · listen · dateien ·
 * collab · plugin:<id>); addon/plugin gating already happened in the shell, so
 * only enabled tabs ever reach here. Panels are wired in as they are built
 * (spec analysis/03-trip-tabs.md); an unbuilt tab shows its empty scroll body
 * while the surrounding chrome (top controls, day chips, dock) stays usable.
 */
export default function MTripTabPanel({ planner, shell, tab }: MTripTabPanelProps) {
  // Trip-page plugin tab — the same sandboxed frame the desktop planner mounts,
  // between the floating top controls and the dock. Both clearances come from the
  // variables TabScroller uses, so the frame cannot drift away from the native
  // tabs: the top one kept the plugin's first row under the z-42 back button, and
  // the bottom one was a copy of 84px that ignored the safe area on the devices
  // that have one. The frame also states its surface, so the plugin knows it is
  // expected to fill and scroll itself rather than report a height.
  //
  // color-scheme is pinned for the same reason both settings mounts pin it:
  // Chromium paints a white canvas behind a transparent frame otherwise.
  if (tab.startsWith('plugin:')) {
    return (
      <div
        className="absolute inset-0 pt-[calc(var(--m-safe-top,12px)+58px)] pb-[calc(var(--bottom-nav-h,84px)+22px)]"
      >
        <PluginFrame
          pluginId={tab.slice('plugin:'.length)}
          tripId={planner.tripId != null ? String(planner.tripId) : null}
          fill
          surface="trip-tab"
          className="h-full w-full [color-scheme:light]"
        />
      </div>
    )
  }
  switch (tab) {
    case 'transports':
      return <MTransportsTab planner={planner} shell={shell} />
    case 'buchungen':
      return <MBookingsTab planner={planner} shell={shell} />
    case 'finanzplan':
      return <MCostsTab planner={planner} shell={shell} />
    case 'dateien':
      return <MFilesTab planner={planner} shell={shell} />
    case 'collab':
      return <MCollabTab planner={planner} shell={shell} />
    case 'listen':
      return <MListsTab planner={planner} shell={shell} />
    // The only tab with two halves of its own: the chain, or the same map showing
    // the stage. Both are this one component, because they share a stage and the
    // switch between them must not lose it.
    case 'roadtrip':
      return <MRoadtripTab planner={planner} shell={shell} tab={tab} />
    // Only ever reached on a large screen: the shell sends a phone back to the plan.
    case 'tour-planner':
      return (
        <LazyPanel id="m-tour-workspace">
          <MTourWorkspace planner={planner} />
        </LazyPanel>
      )
    // The journal the trip links: the Journey addon's own phone screen, moved
    // below the trip's floating top controls: its bars measure from --m-safe-top.
    case 'journal':
      return planner.journalId == null ? null : (
        <div className="absolute inset-0 overflow-hidden [--m-safe-top:calc(var(--m-safe-t,env(safe-area-inset-top,0px))+62px)]">
          <MJourneyDetail journeyId={planner.journalId} embedded />
        </div>
      )
    default:
      return <TabScroller>{null}</TabScroller>
  }
}