mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
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:
@@ -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]);
|
||||
}
|
||||
Reference in New Issue
Block a user