mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
fix(mobile): a stay chip in the timeline header opens the stay, not the day (#2210)
The hotel chips next to the day pill shared its target, so tapping a stay opened the day sheet. A chip now carries its stay and opens it the way the stay card in the day sheet does: the accommodation editor for members who may edit days, otherwise the hotel's place, and the day sheet only when neither applies. Closing the editor returns to the timeline it was opened from instead of surfacing the day sheet, and the chip's accessible name says whether it is a check-in, a check-out or an ongoing stay.
This commit is contained in:
@@ -40,7 +40,8 @@ export type MTripCollabTab = 'chat' | 'notes' | 'polls'
|
||||
/**
|
||||
* Currently open bottom/floating sheet. Well-known ids (owned by the sheets
|
||||
* screen): 'day' (payload { dayId }), 'days', 'mehr', 'note' (payload
|
||||
* { dayId, note? }), 'transport' (payload { reservationId }), 'bract'
|
||||
* { dayId, note? }), 'accommodation' (payload { dayId?, accId?, from? }),
|
||||
* 'transport' (payload { reservationId }), 'bract'
|
||||
* (payload { placeId, dayPicker? }), 'import', 'export', 'members',
|
||||
* 'tripedit', 'bags', 'task'. The place inspector keys off the planner's
|
||||
* place selection instead of a sheet id, and planner-backed editors (place
|
||||
|
||||
@@ -10,7 +10,7 @@ import { fmtTransitDuration } from '../../../../components/Planner/transitDispla
|
||||
import { formatTime } from '../../../../utils/formatters'
|
||||
import { useMPlanTimeline, type MPlanTimelineController } from './useMPlanTimeline'
|
||||
import { cityPillsForDay, weatherIconFor } from './planTimelineModel'
|
||||
import type { PlanRow } from './planTimelineModel'
|
||||
import type { HotelChip, PlanRow } from './planTimelineModel'
|
||||
import { useMPlanDragReorder } from './useMPlanDragReorder'
|
||||
import { useTouchDragBridge } from '../../../../hooks/useTouchDragBridge'
|
||||
import { useIsTouch } from '../../../../hooks/useIsTouch'
|
||||
@@ -56,6 +56,21 @@ export default function MPlanTimeline({ planner, shell }: MPlanTimelineProps) {
|
||||
const daySchedule = usePluginDaySchedule(planner.tripId)
|
||||
const day = tl.day
|
||||
const dayId = day?.id
|
||||
// A stay chip opens the stay, the same way the stay card in the day sheet
|
||||
// does: the editor for members who may edit days, otherwise the hotel's
|
||||
// place. A stay with neither still leads to the day sheet, so the chip
|
||||
// never goes dead (#2210).
|
||||
const openStay = (chip: HotelChip) => {
|
||||
if (!day) return
|
||||
if (canEdit) shell.openSheet('accommodation', { dayId: day.id, accId: chip.accId, from: 'timeline' })
|
||||
else if (chip.placeId != null) planner.handlePlaceClick(chip.placeId)
|
||||
else shell.openSheet('day', { dayId: day.id })
|
||||
}
|
||||
// The icon alone tells check-out from check-in; the accessible name says it.
|
||||
const stayLabel = (chip: HotelChip) => {
|
||||
const kind = chip.variant === 'checkin' ? t('day.checkIn') : chip.variant === 'checkout' ? t('day.checkOut') : t('mobileTrip.stay')
|
||||
return `${kind} · ${chip.name}${chip.time ? ` · ${chip.time.slice(0, 5)}` : ''}`
|
||||
}
|
||||
// Mirrors MDaySheet's own label so the pill and the sheet it opens agree.
|
||||
const dayLabel = day
|
||||
? day.title || t('planner.dayN', { n: day.day_number || planner.days.indexOf(day) + 1 })
|
||||
@@ -159,6 +174,8 @@ export default function MPlanTimeline({ planner, shell }: MPlanTimelineProps) {
|
||||
? `${t('day.overview')} · ${t('day.weatherFor', { name: tl.weatherPlaceName })}`
|
||||
: undefined}
|
||||
onOpenDay={() => shell.openSheet('day', { dayId: day.id })}
|
||||
onOpenStay={openStay}
|
||||
stayLabel={stayLabel}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -396,16 +413,20 @@ function EditHeader({ tl, planner, shell }: {
|
||||
* (check-out / check-in / stay) and the weather chip.
|
||||
*
|
||||
* The day pill leads unconditionally. It used to be the accommodation chip that
|
||||
* carried this, which left a day without a stay — and, with no weather either,
|
||||
* the whole header — with no way into the day sheet at all (#2004).
|
||||
* carried this, which left a day without a stay (and, with no weather either,
|
||||
* the whole header) with no way into the day sheet at all (#2004). Since then
|
||||
* the stay chips have a target of their own: tapping a hotel opens that stay,
|
||||
* not the day (#2210). Only the weather chip still shares the day pill's target.
|
||||
*/
|
||||
function TimelineHeader({ tl, dayLabel, openLabel, weatherLabel, onOpenDay }: {
|
||||
function TimelineHeader({ tl, dayLabel, openLabel, weatherLabel, onOpenDay, onOpenStay, stayLabel }: {
|
||||
tl: MPlanTimelineController
|
||||
dayLabel: string
|
||||
openLabel: string
|
||||
/** Weather-chip label naming the forecast's anchor place (#2167); falls back to openLabel. */
|
||||
weatherLabel?: string
|
||||
onOpenDay: () => void
|
||||
onOpenStay: (chip: HotelChip) => void
|
||||
stayLabel: (chip: HotelChip) => string
|
||||
}) {
|
||||
const WeatherIcon = weatherIconFor(tl.weather?.main)
|
||||
return (
|
||||
@@ -428,7 +449,8 @@ function TimelineHeader({ tl, dayLabel, openLabel, weatherLabel, onOpenDay }: {
|
||||
<button
|
||||
key={chip.key}
|
||||
type="button"
|
||||
onClick={onOpenDay}
|
||||
onClick={() => onOpenStay(chip)}
|
||||
aria-label={stayLabel(chip)}
|
||||
className="flex flex-none items-center gap-[5px] whitespace-nowrap rounded-full bg-[color:var(--m-ic)] px-2.5 py-1 font-geist text-[0.6875rem] font-semibold"
|
||||
>
|
||||
<HotelChipIcon variant={chip.variant} />
|
||||
|
||||
@@ -153,6 +153,9 @@ export interface HotelChip {
|
||||
variant: 'checkout' | 'checkin' | 'stay'
|
||||
name: string
|
||||
time: string | null
|
||||
/** The stay behind the chip, so a tap can open it rather than the day (#2210). */
|
||||
accId: number
|
||||
placeId: number | null
|
||||
}
|
||||
|
||||
const accommodationName = (a: Accommodation): string => a.place_name || a.reservation_title || ''
|
||||
@@ -162,12 +165,13 @@ export function hotelChipsForDay(day: Day, days: Day[], accommodations: Accommod
|
||||
const inRange = accommodations.filter(a => isDayInAccommodationRange(day, a.start_day_id, a.end_day_id, days))
|
||||
const chips: HotelChip[] = []
|
||||
for (const a of inRange) {
|
||||
const stay = { name: accommodationName(a), accId: a.id, placeId: a.place_id ?? null }
|
||||
if (a.end_day_id === day.id) {
|
||||
chips.push({ key: `out-${a.id}`, variant: 'checkout', name: accommodationName(a), time: a.check_out || null })
|
||||
chips.push({ ...stay, key: `out-${a.id}`, variant: 'checkout', time: a.check_out || null })
|
||||
} else if (a.start_day_id === day.id) {
|
||||
chips.push({ key: `in-${a.id}`, variant: 'checkin', name: accommodationName(a), time: a.check_in || null })
|
||||
chips.push({ ...stay, key: `in-${a.id}`, variant: 'checkin', time: a.check_in || null })
|
||||
} else {
|
||||
chips.push({ key: `stay-${a.id}`, variant: 'stay', name: accommodationName(a), time: null })
|
||||
chips.push({ ...stay, key: `stay-${a.id}`, variant: 'stay', time: null })
|
||||
}
|
||||
}
|
||||
const rank = { checkout: 0, checkin: 1, stay: 2 }
|
||||
|
||||
@@ -13,6 +13,8 @@ interface AccommodationPayload {
|
||||
dayId?: number
|
||||
/** Present = edit an existing accommodation, absent = add. */
|
||||
accId?: number
|
||||
/** Opened from the timeline's stay chip: closing returns there, not to the day sheet (#2210). */
|
||||
from?: 'timeline'
|
||||
}
|
||||
|
||||
interface HotelForm {
|
||||
@@ -72,10 +74,14 @@ export default function MAccommodationSheet({ planner, shell }: MTripSheetsProps
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [open, payload.dayId, payload.accId])
|
||||
|
||||
// Cancelling / saving returns to the day sheet it was opened from — opened for
|
||||
// an edit there is no dayId in the payload, so fall back to the stay's own
|
||||
// start day instead of leaving the day sheet without one.
|
||||
const back = () => shell.openSheet('day', { dayId: payload.dayId ?? editing?.start_day_id })
|
||||
// Cancelling / saving returns to the day sheet it was opened from. Opened for
|
||||
// an edit there may be no dayId in the payload, so fall back to the stay's own
|
||||
// start day instead of leaving the day sheet without one. Opened straight from
|
||||
// the timeline's stay chip there is no day sheet to return to, so just close.
|
||||
const back = () => {
|
||||
if (payload.from === 'timeline') shell.closeSheet()
|
||||
else shell.openSheet('day', { dayId: payload.dayId ?? editing?.start_day_id })
|
||||
}
|
||||
|
||||
const firstId = days[0]?.id
|
||||
const lastId = days[days.length - 1]?.id
|
||||
|
||||
Reference in New Issue
Block a user