From 443a4fd488ca721f1912d3cb8dbc7d7f6669fdf9 Mon Sep 17 00:00:00 2001 From: Maurice Date: Fri, 27 Nov 2026 23:27:17 +0100 Subject: [PATCH] refactor(mobile): open what was shared into a trip from a hook of its own The trip shell had grown past the 1000-line limit with the shared map link. Both effects that open a shared item in the trip, the booking import and the new place sheet, now live in useSharedIntoTrip beside the share store. --- client/src/mobile/screens/trip/MTripShell.tsx | 26 +++++-------------- client/src/native/useSharedIntoTrip.ts | 21 +++++++++++++++ 2 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 client/src/native/useSharedIntoTrip.ts diff --git a/client/src/mobile/screens/trip/MTripShell.tsx b/client/src/mobile/screens/trip/MTripShell.tsx index a6d82bfd7..a72ba2992 100644 --- a/client/src/mobile/screens/trip/MTripShell.tsx +++ b/client/src/mobile/screens/trip/MTripShell.tsx @@ -9,7 +9,7 @@ import { pickDockTabs } from './dockTabs' import MBadge from '../../components/MBadge' import MIconBtn from '../../components/MIconBtn' import { useActivePill } from '../../components/useActivePill' -import { useSharedImportStore } from '../../../native/sharedFiles' +import { useSharedIntoTrip } from '../../../native/useSharedIntoTrip' import MPlanTimeline from './plan/MPlanTimeline' import MMapArea from './map/MMapArea' import MPlacesBrowser from './places/MPlacesBrowser' @@ -316,25 +316,11 @@ export default function MTripShell({ }) }, [railDayId, days, dayRail]) // The active day's pill glides to the next chip rather than jumping there. - // A booking document shared to TREK, and this trip picked for it: open the import. - const sharedTripId = useSharedImportStore(s => s.tripId) - const { setBookingImportKind, setShowBookingImport } = planner - useEffect(() => { - if (sharedTripId == null || sharedTripId !== Number(tripId)) return - setBookingImportKind('bookings') - setShowBookingImport(true) - }, [sharedTripId, tripId, setBookingImportKind, setShowBookingImport]) - // A map link shared to TREK and this trip picked for it (#2582): the new place - // sheet opens, and its search looks the link up (MPlaceEditSheet). - const sharedPlaceTripId = useSharedImportStore(s => s.placeLink?.tripId ?? null) - const { setEditingPlace, setEditingAssignmentId, setPrefillCoords, setShowPlaceForm } = planner - useEffect(() => { - if (sharedPlaceTripId == null || sharedPlaceTripId !== Number(tripId)) return - setEditingPlace(null) - setEditingAssignmentId(null) - setPrefillCoords(null) - setShowPlaceForm(true) - }, [sharedPlaceTripId, tripId, setEditingPlace, setEditingAssignmentId, setPrefillCoords, setShowPlaceForm]) + // Something shared to TREK and sent to this trip: the booking import, or a new place (#2582). + useSharedIntoTrip(Number(tripId), { + bookingImport: () => { planner.setBookingImportKind('bookings'); planner.setShowBookingImport(true) }, + newPlace: () => { planner.setEditingPlace(null); planner.setEditingAssignmentId(null); planner.setPrefillCoords(null); planner.setShowPlaceForm(true) }, + }) // The day strip says when it runs on past an edge (a long trip, a narrow pane). const dayFade = useEdgeFade(dayRail) const dayPill = useActivePill(dayRail, '[aria-current="true"]', `${railDayId}:${days.map(d => d.id).join(',')}:${language}`) diff --git a/client/src/native/useSharedIntoTrip.ts b/client/src/native/useSharedIntoTrip.ts new file mode 100644 index 000000000..ac84c40ea --- /dev/null +++ b/client/src/native/useSharedIntoTrip.ts @@ -0,0 +1,21 @@ +import { useEffect, useEffectEvent } from 'react'; + +import { useSharedImportStore } from './sharedFiles'; + +/** + * What was shared to TREK and sent to this trip (native/sharedFiles.ts), opened + * where it belongs once the trip is on screen: a booking document in the booking + * import, a map link in the new place sheet, whose search looks it up (#2582). + */ +export function useSharedIntoTrip(tripId: number, open: { bookingImport: () => void; newPlace: () => void }): void { + const bookingTripId = useSharedImportStore((s) => s.tripId); + const placeTripId = useSharedImportStore((s) => s.placeLink?.tripId ?? null); + const openBookingImport = useEffectEvent(() => open.bookingImport()); + const openNewPlace = useEffectEvent(() => open.newPlace()); + useEffect(() => { + if (bookingTripId != null && bookingTripId === tripId) openBookingImport(); + }, [bookingTripId, tripId]); + useEffect(() => { + if (placeTripId != null && placeTripId === tripId) openNewPlace(); + }, [placeTripId, tripId]); +}