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.
This commit is contained in:
Maurice
2026-11-27 23:27:17 +01:00
parent 8d5d34fbb3
commit 443a4fd488
2 changed files with 27 additions and 20 deletions
+6 -20
View File
@@ -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}`)
+21
View File
@@ -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]);
}