mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
refactor(mobile): move the trip shell's tab switch into a hook of its own, under the size limit
This commit is contained in:
@@ -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.",
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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');
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user