mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 23:27:31 +00:00
fix(map): prevent trip overview and day details from overlapping
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import type { Ref } from 'react'
|
||||
import { AlertTriangle, Route } from 'lucide-react'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import { MapTogglePill } from './MapTogglePill'
|
||||
@@ -6,6 +7,9 @@ import { routeDistanceLabel } from './tripRouteLabels'
|
||||
import type { TripRouteOverview as Overview } from './useTripRouteOverview'
|
||||
import type { DistanceUnit } from '../../types'
|
||||
|
||||
export const TRIP_OVERVIEW_MAX_WIDTH = 320
|
||||
export const TRIP_OVERVIEW_INSET = 14
|
||||
|
||||
/**
|
||||
* Toggle for the whole-trip route overview (#1736). Same frosted shell as the other
|
||||
* map controls, so it lines up with the compass and the layer switcher.
|
||||
@@ -29,13 +33,14 @@ export function TripRouteOverviewPill({ active, onToggle }: { active: boolean; o
|
||||
* One component for both shells: the phone and the desktop place it differently but the
|
||||
* rows are the same rows, and a second copy of them is a second thing to keep in step.
|
||||
*/
|
||||
export function TripRouteOverviewPanel({ overview, unit, selectedDayId, onSelectDay, maxWidth = 320 }: {
|
||||
export function TripRouteOverviewPanel({ overview, unit, selectedDayId, onSelectDay, maxWidth = TRIP_OVERVIEW_MAX_WIDTH, cardRef }: {
|
||||
overview: Overview
|
||||
unit: DistanceUnit
|
||||
selectedDayId?: number | null
|
||||
onSelectDay?: (dayId: number) => void
|
||||
/** How wide the card may grow before day names start to ellipsize. */
|
||||
maxWidth?: number
|
||||
cardRef?: Ref<HTMLDivElement>
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
if (!overview.days.length) return null
|
||||
@@ -45,6 +50,7 @@ export function TripRouteOverviewPanel({ overview, unit, selectedDayId, onSelect
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={cardRef}
|
||||
data-testid="trip-overview-panel"
|
||||
style={{
|
||||
pointerEvents: 'auto', borderRadius: 14, overflow: 'hidden',
|
||||
|
||||
@@ -35,4 +35,12 @@ describe('centredMapCard', () => {
|
||||
expect(resolve(box.width, 1920)).toBe(800);
|
||||
expect(resolve(box.centre, 1920)).toBe(960);
|
||||
});
|
||||
|
||||
it('keeps the whole-trip toggle reachable beside the day card', () => {
|
||||
const box = centredMapCard(350, 310, { clearPill: true, rightGap: 74 });
|
||||
const width = resolve(box.width, 1280);
|
||||
const centre = resolve(box.centre, 1280);
|
||||
expect(centre - width / 2).toBeGreaterThanOrEqual(350 + 62);
|
||||
expect(centre + width / 2).toBeLessThanOrEqual(1280 - 310 - 74);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@ const PILL_CLEARANCE = MAP_LAYER_SWITCHER_INSET + MAP_ROUND_CONTROL_SIZE + 8;
|
||||
* it and gives up the few pixels it needs, a wide map keeps it exactly centred.
|
||||
* The phone shows these cards as sheets with no pill beside them, so it leaves
|
||||
* `clearPill` off.
|
||||
* `rightGap` reserves room for a map control on the other edge.
|
||||
*
|
||||
* `extent` is what the card is placed in: '100%' of the map, or '100vw' for the
|
||||
* fixed day panel.
|
||||
@@ -29,13 +30,21 @@ const PILL_CLEARANCE = MAP_LAYER_SWITCHER_INSET + MAP_ROUND_CONTROL_SIZE + 8;
|
||||
export function centredMapCard(
|
||||
leftWidth: number,
|
||||
rightWidth: number,
|
||||
{ extent = '100%', clearPill = false }: { extent?: string; clearPill?: boolean } = {}
|
||||
{
|
||||
extent = '100%',
|
||||
clearPill = false,
|
||||
rightGap = EDGE_GAP,
|
||||
}: { extent?: string; clearPill?: boolean; rightGap?: number } = {}
|
||||
): { centre: string; width: string } {
|
||||
const free = `(${extent} - ${leftWidth}px - ${rightWidth}px)`;
|
||||
const centre = `calc(${leftWidth}px + ${free} / 2)`;
|
||||
if (!clearPill) return { centre, width: `min(800px, calc(${free} - ${2 * EDGE_GAP}px))` };
|
||||
const width = `min(800px, calc(${free} - ${PILL_CLEARANCE + EDGE_GAP}px))`;
|
||||
return { width, centre: `max(${centre}, calc(${leftWidth}px + ${PILL_CLEARANCE}px + ${width} / 2))` };
|
||||
const leftGap = clearPill ? PILL_CLEARANCE : EDGE_GAP;
|
||||
const width = `min(800px, calc(${free} - ${leftGap + rightGap}px))`;
|
||||
const centreClearingLeft = `max(${centre}, calc(${leftWidth}px + ${leftGap}px + ${width} / 2))`;
|
||||
if (rightGap === EDGE_GAP) return { width, centre: clearPill ? centreClearingLeft : centre };
|
||||
|
||||
const maxCentre = `calc(${extent} - ${rightWidth + rightGap}px - ${width} / 2)`;
|
||||
return { width, centre: `min(${centreClearingLeft}, ${maxCentre})` };
|
||||
}
|
||||
|
||||
/** How a card that floats over the map is placed there, read by `centredMapCard`. */
|
||||
|
||||
@@ -49,7 +49,7 @@ export function useTripRouteOverview(
|
||||
vias?: TripRouteVias,
|
||||
/** MDT-02: where the stages of the trip's multi-day tours run, so a day holding one draws that stage. */
|
||||
tourStageStops?: TourStageStops,
|
||||
): TripRouteOverview {
|
||||
) {
|
||||
const optimizeFromAccommodation = useSettingsStore(s => s.settings.optimize_from_accommodation)
|
||||
const toursEnabled = useTripAddonEnabled(tripId, 'tours')
|
||||
// Leg text is formatted at compute time, so a km↔mi switch has to re-run (#1300).
|
||||
@@ -131,5 +131,6 @@ export function useTripRouteOverview(
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [planKey, tripId, distanceUnit])
|
||||
|
||||
return result
|
||||
const hasPlannedRoute = plan.length > 0
|
||||
return useMemo(() => ({ ...result, hasPlannedRoute }), [result, hasPlannedRoute])
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useRef, useId, type ReactNode } from 'react'
|
||||
import React, { useEffect, useRef, useId, type ReactNode, type Ref } from 'react'
|
||||
import { X, CloudRain, Wind, Droplets, Sunrise, Sunset, Hotel, Calendar, MapPin, LogIn, LogOut, Pencil, ChevronsDown, ChevronsUp, ArrowRight, Check, Moon, type LucideIcon } from 'lucide-react'
|
||||
import type { WeatherResult } from '@trek/shared'
|
||||
import { usePluginViewContributions, PluginCardFooter } from '../Plugins/PluginContributions'
|
||||
@@ -53,6 +53,8 @@ interface DayDetailPanelProps {
|
||||
onAccommodationChange: () => void
|
||||
leftWidth?: number
|
||||
rightWidth?: number
|
||||
rightGap?: number
|
||||
panelRef?: Ref<HTMLDivElement>
|
||||
collapsed?: boolean
|
||||
onToggleCollapse?: () => void
|
||||
mobile?: boolean
|
||||
@@ -73,7 +75,7 @@ interface DayDetailPanelProps {
|
||||
* head band that folds the card away, then the weather, the bookings of the
|
||||
* day and where the night is spent, each under its own label.
|
||||
*/
|
||||
export default function DayDetailPanel({ day, days, places, categories = [], tripId, assignments, reservations = [], lat, lng, onClose, onAccommodationChange, leftWidth = 0, rightWidth = 0, collapsed: collapsedProp = false, onToggleCollapse, mobile = false, onUpdateDayTitle, weatherPlaceName = null, openStayPicker = false, onStayPickerOpened, onOpenBooking }: DayDetailPanelProps) {
|
||||
export default function DayDetailPanel({ day, days, places, categories = [], tripId, assignments, reservations = [], lat, lng, onClose, onAccommodationChange, leftWidth = 0, rightWidth = 0, rightGap, panelRef, collapsed: collapsedProp = false, onToggleCollapse, mobile = false, onUpdateDayTitle, weatherPlaceName = null, openStayPicker = false, onStayPickerOpened, onOpenBooking }: DayDetailPanelProps) {
|
||||
const { t, language } = useTranslation()
|
||||
const can = useCanDo()
|
||||
const toast = useToast()
|
||||
@@ -184,10 +186,10 @@ export default function DayDetailPanel({ day, days, places, categories = [], tri
|
||||
setShowHotelPicker('edit')
|
||||
}
|
||||
const removeAccommodation = (acc: Accommodation) => { handleRemoveAccommodation(acc).catch(showError) }
|
||||
const mapCard = centredMapCard(leftWidth, rightWidth, { extent: '100vw', clearPill: !mobile })
|
||||
const mapCard = centredMapCard(leftWidth, rightWidth, { extent: '100vw', clearPill: !mobile, rightGap })
|
||||
|
||||
return (
|
||||
<div className="fixed z-50" style={{ bottom: 'calc(var(--bottom-nav-h) + 20px)', left: mapCard.centre, transform: 'translateX(-50%)', width: mapCard.width, ...(mobile ? { zIndex: 10000 } : null), fontFamily: 'var(--font-system)' }}>
|
||||
<div ref={panelRef} className="fixed z-50" style={{ bottom: 'calc(var(--bottom-nav-h) + 20px)', left: mapCard.centre, transform: 'translateX(-50%)', width: mapCard.width, ...(mobile ? { zIndex: 10000 } : null), fontFamily: 'var(--font-system)' }}>
|
||||
<div ref={cardRef}
|
||||
className="flex flex-col overflow-hidden rounded-[20px] border border-edge-faint bg-surface-elevated shadow-popover backdrop-blur-[40px] backdrop-saturate-[1.8]"
|
||||
style={{ maxHeight: collapsed ? 'none' : '60vh' }}>
|
||||
|
||||
@@ -158,6 +158,18 @@ function dayHeader(title: string) {
|
||||
}
|
||||
|
||||
describe('DayPlanSidebar day header', () => {
|
||||
it('opens the selected day details while the whole-trip overview is active', async () => {
|
||||
const user = userEvent.setup();
|
||||
const day = buildDay({ id: 10, date: '2025-06-01', title: 'My Day' });
|
||||
const props = makeDefaultProps({ days: [day], selectedDayId: day.id });
|
||||
render(<DayPlanSidebar {...props} openSelectedDayDetail />);
|
||||
|
||||
await user.click(screen.getByText('My Day'));
|
||||
|
||||
expect(props.onSelectDay).toHaveBeenCalledWith(day.id);
|
||||
expect(props.onDayDetail).toHaveBeenCalledWith(day);
|
||||
});
|
||||
|
||||
it('FE-PLANNER-DAYPLAN-176: a transfer day lists the check-out hotel before the check-in one', async () => {
|
||||
const user = userEvent.setup();
|
||||
const days = [
|
||||
|
||||
@@ -104,6 +104,7 @@ export interface DayPlanSidebarProps {
|
||||
categories: Category[]
|
||||
assignments: AssignmentsMap
|
||||
selectedDayId: number | null
|
||||
openSelectedDayDetail?: boolean
|
||||
selectedPlaceId: number | null
|
||||
selectedAssignmentId: number | null
|
||||
onSelectDay: (dayId: number | null, skipFit?: boolean) => void
|
||||
@@ -1480,12 +1481,11 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar(props: DayPlanSidebarP
|
||||
<div className={`scroll-container flex flex-col gap-2 p-2${hasDragged ? '' : ' trek-stagger'}`} style={{ flex: 1, overflowY: 'auto', minHeight: 0 }} ref={scrollContainerRef} onScroll={(e) => onScrollTopChange?.((e.currentTarget as HTMLElement).scrollTop)}>
|
||||
{days.map((day, index) => {
|
||||
const isSelected = selectedDayId === day.id
|
||||
// Shared by the click and the key handler so the two can never drift
|
||||
// apart — pressing Enter on the row has to toggle, not just select.
|
||||
// Named for the selection, not the expand/collapse `toggleDay` above.
|
||||
// An already-selected day can reopen its details from the overview.
|
||||
const toggleDaySelection = () => {
|
||||
if (isSelected) { onSelectDay(null); if (onDayDetail) onDayDetail(null) }
|
||||
else { onSelectDay(day.id); if (onDayDetail) onDayDetail(day) }
|
||||
const dayToOpen = isSelected && !props.openSelectedDayDetail ? null : day
|
||||
onSelectDay(dayToOpen?.id ?? null)
|
||||
onDayDetail?.(dayToOpen)
|
||||
}
|
||||
const isExpanded = expandedDays.has(day.id)
|
||||
const da = getDayAssignments(day.id)
|
||||
|
||||
Reference in New Issue
Block a user