mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 18:34:09 +00:00
fix(tours): keep one card in the map corner and offer only ways that change a section
While the other ways of a hike's section were compared, a click on a via ferrata or a place on the map opened its card in the same corner, stacked over the comparison. The corner now holds one card: whichever opened last stays and the other closes, before paint, so the two never show together. The router's first answer between the two ends is its own way under the hike's rules, which the tour already routes the section by. Offered as a choice, taking it only planned the leg again, usually to the same line, and the card closed without "Way taken" or an undo step. It is no longer offered, so every way taken is held by shaping points, changes the route and can be taken back in one step.
This commit is contained in:
@@ -612,6 +612,55 @@ describe('TourPlannerMapStage', () => {
|
||||
expect(appliedHint.hold).toHaveBeenCalledWith(true);
|
||||
});
|
||||
|
||||
describe('one card in the corner (RTE-02)', () => {
|
||||
const waypoints = [
|
||||
{ id: 'w1', lat: 46, lng: 7 },
|
||||
{ id: 'w2', lat: 46.2, lng: 7.2 },
|
||||
];
|
||||
const comparison = {
|
||||
leg: { fromId: 'w1', toId: 'w2', from: { lat: 46, lng: 7 }, to: { lat: 46.2, lng: 7.2 }, costing: {}, key: 'k' },
|
||||
phase: 'loading',
|
||||
variants: [],
|
||||
selected: null,
|
||||
proving: false,
|
||||
notice: null,
|
||||
};
|
||||
const comparingPlanner = (legVariants: ReturnType<typeof idleLegVariants>) =>
|
||||
planner('new-draft', { waypoints, route: null, canEdit: true, legVariants: { ...legVariants, comparison } });
|
||||
|
||||
/** Picks the via ferrata on the flat map, as a click on its line does. */
|
||||
function pickFerrata() {
|
||||
act(() => stage.flatMap.props?.ferrataLayer?.onToggle());
|
||||
const group = stage.flatMap.props?.ferrataLayer?.groups[0];
|
||||
if (!group) throw new Error('no group');
|
||||
act(() => stage.flatMap.props?.ferrataLayer?.onSelect(group, FERRATA, { lat: 46.52, lng: 11.8 }));
|
||||
}
|
||||
|
||||
it('FE-PAGE-TOURSTAGE-021: a via ferrata picked while a section is compared closes the comparison, so one card stands there', () => {
|
||||
const legVariants = idleLegVariants();
|
||||
const view = renderStage(comparingPlanner(legVariants));
|
||||
expect(screen.getByTestId('leg-variants-overlay')).toBeInTheDocument();
|
||||
pickFerrata();
|
||||
expect(legVariants.close).toHaveBeenCalledTimes(1);
|
||||
|
||||
view.rerender(<TourPlannerMapStage {...stageProps(planner('new-draft', { waypoints, legVariants }))} />);
|
||||
expect(screen.getByTestId('ferrata-detail-overlay')).toBeInTheDocument();
|
||||
expect(screen.queryByTestId('leg-variants-overlay')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-PAGE-TOURSTAGE-022: a comparison opened over a via ferrata card closes that card instead', () => {
|
||||
const legVariants = idleLegVariants();
|
||||
const view = renderStage(planner('new-draft', { waypoints, legVariants }));
|
||||
pickFerrata();
|
||||
expect(screen.getByTestId('ferrata-detail-overlay')).toBeInTheDocument();
|
||||
|
||||
view.rerender(<TourPlannerMapStage {...stageProps(comparingPlanner(legVariants))} />);
|
||||
expect(screen.queryByTestId('ferrata-detail-overlay')).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId('leg-variants-overlay')).toBeInTheDocument();
|
||||
expect(legVariants.close).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('map layers per tour type (P2B-06/07, PAD-04, PAD-10)', () => {
|
||||
const flat = () => stage.flatMap.props as MapViewProps;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import { useSettingsStore } from '../../store/settingsStore';
|
||||
import { publishTourFerrataCrossings } from '../../store/tourFerrataCrossingStore';
|
||||
import { publishTourMapViewport } from '../../store/tourMapViewportStore';
|
||||
import { useFerrataAdopt } from './useFerrataAdopt';
|
||||
import { useOneCornerCard } from './useOneCornerCard';
|
||||
import { useTourMapPoints } from './useTourMapPoints';
|
||||
import { useTourStageLayers } from './useTourStageLayers';
|
||||
import { useTrackLinePick } from './useTrackLinePick';
|
||||
@@ -169,6 +170,13 @@ export function TourPlannerMapStage({
|
||||
const poiMarkers = useTourPoiMarkers();
|
||||
// RTE-02: while other ways of a section are compared, a click on the line sets nothing on it.
|
||||
const comparing = tourPlanner.legVariants.comparison !== null;
|
||||
// The comparison's card shares the corner with the others: the one opened last stays.
|
||||
useOneCornerCard({
|
||||
comparing,
|
||||
closeComparison: tourPlanner.legVariants.close,
|
||||
ferrataOpen: !!ferrataSelected,
|
||||
closeFerrata: ferrata.close,
|
||||
});
|
||||
const shapeAt = useShapingClick(tourPlanner, { editable: !!waypoints.onMove, picking: pickOnLine || comparing });
|
||||
// What each panel covers of the map, a collapsed one its rail.
|
||||
const leftInset = leftHidden ? 56 : leftPanelPx;
|
||||
@@ -282,7 +290,7 @@ export function TourPlannerMapStage({
|
||||
insetEnd={cardInsetEnd}
|
||||
{...ferrataCardPlacement(terrain3d, bottomRowTop, terrainLegend)}
|
||||
/>
|
||||
{/* RTE-02: the ways of one section compared, in the same corner as the other cards. */}
|
||||
{/* RTE-02: the ways of one section compared, in the same corner as the other cards and never over one. */}
|
||||
<LegVariantsOverlay
|
||||
planner={tourPlanner}
|
||||
insetEnd={cardInsetEnd}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { useLayoutEffect, useRef } from 'react';
|
||||
import { useSelectedPoi } from '../../components/Tours/poi/useTourPoiSearch';
|
||||
import { selectPaddleObstacle, usePaddleObstacleStore } from '../../store/paddleObstacleStore';
|
||||
import { useTourPoiStore } from '../../store/tourPoiStore';
|
||||
|
||||
/**
|
||||
* The corner over the planner map holds one card at a time. A via ferrata's,
|
||||
* a paddle object's and a place's card close on any press outside them, so
|
||||
* the press that opens the next one has closed the last already. The
|
||||
* comparison of a section's ways (RTE-02) stays up through presses on the map,
|
||||
* so it is kept apart here: whichever of it and the others opened last stays,
|
||||
* and the other closes. Laid out before paint, so two cards never show
|
||||
* stacked in the corner, not even for a frame.
|
||||
*/
|
||||
export function useOneCornerCard({
|
||||
comparing,
|
||||
closeComparison,
|
||||
ferrataOpen,
|
||||
closeFerrata,
|
||||
}: {
|
||||
comparing: boolean;
|
||||
closeComparison: () => void;
|
||||
ferrataOpen: boolean;
|
||||
closeFerrata: () => void;
|
||||
}): void {
|
||||
const paddleOpen = usePaddleObstacleStore((state) => state.selectedRef !== null);
|
||||
const poiOpen = useSelectedPoi() !== null;
|
||||
const selectPoi = useTourPoiStore((state) => state.select);
|
||||
const otherOpen = ferrataOpen || paddleOpen || poiOpen;
|
||||
const was = useRef({ comparing, otherOpen });
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const before = was.current;
|
||||
was.current = { comparing, otherOpen };
|
||||
if (!comparing || !otherOpen) return;
|
||||
// A card picked on the map while comparing takes the corner; a comparison opened over a card does.
|
||||
if (!before.otherOpen) {
|
||||
closeComparison();
|
||||
return;
|
||||
}
|
||||
closeFerrata();
|
||||
selectPaddleObstacle(null);
|
||||
selectPoi(null);
|
||||
}, [closeComparison, closeFerrata, comparing, otherOpen, selectPoi]);
|
||||
}
|
||||
Reference in New Issue
Block a user