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.

refactor(mobile): move the trip shell's tab switch into a hook of its own, under the size limit

Mauriced6905435ae62
diff --git a/client/scripts/feature-pairs.json b/client/scripts/feature-pairs.json
index a28ce59ab..e3440ef9a 100644
--- a/client/scripts/feature-pairs.json
+++ b/client/scripts/feature-pairs.json
@@ -1126,6 +1126,7 @@
"src/mobile/screens/trip/MTripRail.tsx": "Phone shell only; the trip's sections on the leading edge of a wide window in place of the dock, with the tabs and handlers MTripShell hands in.",
"src/mobile/screens/trip/MTripShellParts.tsx": "Markup only; small pieces of MTripShell's top controls (segment pill, compact toggle, document sync button), with the state and handlers MTripShell hands in.",
"src/mobile/screens/trip/dockTabs.ts": "Phone only helper that picks which trip tabs get a seat in the mobile dock.",
+ "src/mobile/screens/trip/useTripTabSwitch.ts": "Phone shell only; switches the section the dock and a notification link open, and the collab part a message link means. The desktop switches through useTripPlanner alone.",
"src/mobile/screens/trip/lib/dayNotes.ts": "Phone only helper that splits a leading time off a day note for the plan timeline.",
"src/mobile/screens/trip/map/MMapArea.tsx": "Phone map stage framing; already shares usePoiExplore and useMergedMapPois with the desktop trip planner.",
"src/mobile/screens/trip/places/MPlacesBulkCategorySheet.tsx": "Markup only; categories and the pick handler come through props from MPlacesBrowser.",
diff --git a/client/src/mobile/screens/trip/MTripShell.tsx b/client/src/mobile/screens/trip/MTripShell.tsx
index 79818e30d..0328db108 100644
--- a/client/src/mobile/screens/trip/MTripShell.tsx
+++ b/client/src/mobile/screens/trip/MTripShell.tsx
@@ -36,6 +36,7 @@ import { useShortcuts } from '../../keyboard/useShortcuts'
import { tripCreateIntent } from '../../../components/Layout/useCreateAction'
import MDockScrim from '../../components/MDockScrim'
import { setTabHeadSlot } from './tabHeadSlot'
+import { useTripTabSwitch } from './useTripTabSwitch'
/**
* Mobile trip screen frame. Owns the chrome the design shares across every
@@ -335,17 +336,7 @@ export default function MTripShell({
if (trTab === 'tour-planner' && !wide) planner.handleTabChange('plan')
}, [trTab, wide, planner.handleTabChange])
- const setTrTab = (tabId: string) => {
- planner.handleTabChange(tabId)
- if (mode === 'browse') setMode('go')
- }
-
- // A notification link opens its tab the way the dock does, and a message one the chat.
- useEffect(() => {
- if (!planner.tabLink) return
- setMode(m => (m === 'browse' ? 'go' : m))
- if (planner.tabLink.tab === 'collab') setCollabTab('chat')
- }, [planner.tabLink])
+ const setTrTab = useTripTabSwitch(planner, mode, setMode, setCollabTab)
const setTravelMode = (next: MTripMode) => {
setBrowseFromEdit(next === 'browse' && mode === 'edit')
diff --git a/client/src/mobile/screens/trip/useTripTabSwitch.ts b/client/src/mobile/screens/trip/useTripTabSwitch.ts
new file mode 100644
index 000000000..b21338fcc
--- /dev/null
+++ b/client/src/mobile/screens/trip/useTripTabSwitch.ts
@@ -0,0 +1,32 @@
+import { useEffect } from 'react';
+import type { MTripCollabTab, MTripMode } from './MTripShell';
+
+interface TabSwitchPlanner {
+ handleTabChange: (tabId: string) => void;
+ /** The last `?tab=` link the planner took, counted so the same tab twice still lands. */
+ tabLink: { tab: string; seq: number } | null;
+}
+
+/**
+ * How the phone shell changes the trip's section. A tap on the dock goes through the
+ * planner and leaves the places browser; a notification link the planner took does the
+ * same, and a message one opens the chat rather than the collab part last on screen.
+ */
+export function useTripTabSwitch(
+ planner: TabSwitchPlanner,
+ mode: MTripMode,
+ setMode: (update: (mode: MTripMode) => MTripMode) => void,
+ setCollabTab: (tab: MTripCollabTab) => void
+): (tabId: string) => void {
+ const { tabLink } = planner;
+ useEffect(() => {
+ if (!tabLink) return;
+ setMode((m) => (m === 'browse' ? 'go' : m));
+ if (tabLink.tab === 'collab') setCollabTab('chat');
+ }, [tabLink, setMode, setCollabTab]);
+
+ return (tabId: string) => {
+ planner.handleTabChange(tabId);
+ if (mode === 'browse') setMode(() => 'go');
+ };
+}