fix(map): prevent trip overview and day details from overlapping

This commit is contained in:
Luffy
2026-11-27 12:05:42 +08:00
committed by Maurice
parent 3dd63331bc
commit 7a57c58dd0
20 changed files with 475 additions and 52 deletions
@@ -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)