mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
aacc7f2c8d
"Open packing list" switched to the Lists tab but left it on whichever sub-tab was open last, so someone who had been in the to-dos landed there. It now picks the packing side first, and a Lists tab already on screen follows the choice; storage that is blocked no longer throws either. With the Packing addon off, "Remove link" let go of the link on one click, and the link cannot be made again until Packing is back on. It now opens the tour's packing dialog with only the dimmed link and the Remove link and Cancel buttons, so nothing changes without a second, deliberate click.
58 lines
2.4 KiB
TypeScript
58 lines
2.4 KiB
TypeScript
import type { TourListItem } from '@trek/shared';
|
|
import { rememberListsSubTab } from '../../hooks/useListsSubTab';
|
|
import { tourRepo } from '../../repo/tourRepo';
|
|
import { useTripStore } from '../../store/tripStore';
|
|
import type { Place } from '../../types';
|
|
import type { useTripPlanner } from './useTripPlanner';
|
|
|
|
/**
|
|
* What the tour's detail does beyond a place's: a rename reloads the tours,
|
|
* a reimport from its source check (MF-03) takes the new snapshot in and opens
|
|
* it, "save as new tour" (P2C-07) makes the copy and opens it under a name
|
|
* that says it is one, so renaming it is the next step, and a recorded track
|
|
* assigned or taken off (ACT-01) is taken into the lists.
|
|
*/
|
|
export function useTourDetailActions(planner: ReturnType<typeof useTripPlanner>) {
|
|
const { invalidateTourPlaceIds, reloadTourPlaceIds, t, toast, tripActions, tripId, upsertTour } = planner;
|
|
|
|
/** A tour that just came in: in the lists and on the map. */
|
|
const bringIn = async (tour: TourListItem) => {
|
|
upsertTour(tour);
|
|
await useTripStore.getState().refreshPlaces(tripId);
|
|
void invalidateTourPlaceIds({ placeIds: [tour.place_id] });
|
|
};
|
|
/** ...and its detail open. */
|
|
const takeIn = async (tour: TourListItem) => {
|
|
await bringIn(tour);
|
|
planner.handlePlaceClick(tour.place_id);
|
|
};
|
|
|
|
return {
|
|
onUpdatePlace: async (placeId: number, data: Partial<Place>) => {
|
|
await tripActions.updatePlace(tripId, placeId, data);
|
|
await reloadTourPlaceIds();
|
|
},
|
|
onSourceReimported: takeIn,
|
|
/** ACT-01: a recorded track assigned, taken off or imported; the lists read these tours again. */
|
|
onToursChanged: (placeIds: number[]) => invalidateTourPlaceIds({ placeIds }),
|
|
/** LIB-02: a tour taken over from another trip; the tours rail opens it in the planner. */
|
|
onTakenOver: bringIn,
|
|
/** P2D-XD-01: the packing list a tour points at, in the trip's Lists tab, on its packing side. */
|
|
onOpenPacking: () => {
|
|
planner.setSelectedPlaceId(null);
|
|
rememberListsSubTab(tripId, 'packing');
|
|
planner.handleTabChange('listen');
|
|
},
|
|
onSaveAsNew: async (tour: TourListItem) => {
|
|
try {
|
|
const name = t('tours.copy.name', { name: tour.name }).slice(0, 255);
|
|
const { tour: copy } = await tourRepo.copy(tripId, tour.place_id, name);
|
|
await takeIn(copy);
|
|
toast.success(t('tours.copy.saved'));
|
|
} catch {
|
|
toast.error(t('tours.copy.failed'));
|
|
}
|
|
},
|
|
};
|
|
}
|