Files
TREK/client/src/native/useSharedIntoTrip.ts
T
Maurice 443a4fd488 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.
2026-11-27 23:27:17 +01:00

22 lines
1005 B
TypeScript

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]);
}