mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
fix(dayplan): calmer day dialogs, and the shrink question side by side
The day dialog hangs from a fixed top edge, so switching to the delete question only moves its bottom edge, and the question opens at its top with the focus on Cancel. Cancel, Close and the quiet add share one outline; the dated add is drawn in the accent instead of filled with it. Dates in the dialog, its hints and the new-day toast read the way the day list writes them, and captions use the muted text colour for contrast. A stay booked twice is named once in the warning. On the phone the dated pill shows only its date, so both pills fit side by side. When the trip dialog asks both how bookings follow a moved start and which days the new dates remove, the two now stand side by side in a wide dialog instead of one long column.
This commit is contained in:
@@ -86,6 +86,16 @@ const byNumber = (a: Day, b: Day): number => (a.day_number ?? 0) - (b.day_number
|
||||
/** A reservation's link to a stay, which the wire carries as a number or a string. */
|
||||
const stayOf = (r: Reservation): number | null => (r.accommodation_id == null ? null : Number(r.accommodation_id))
|
||||
|
||||
/**
|
||||
* Each stay once. The stays list joins in the bookings, so a stay with two of
|
||||
* them comes over the wire twice; the warning names it once all the same, and
|
||||
* counts its bookings through describeStay.
|
||||
*/
|
||||
function distinctStays(stays: Accommodation[]): Accommodation[] {
|
||||
const seen = new Set<number>()
|
||||
return stays.filter(stay => !seen.has(stay.id) && seen.add(stay.id))
|
||||
}
|
||||
|
||||
/** The bookings linked to a stay, its first booking title, and the name the list gives it. */
|
||||
function describeStay(stay: Accommodation, data: DayContentData) {
|
||||
const linked = data.reservations.filter(r => stayOf(r) === stay.id)
|
||||
@@ -121,7 +131,7 @@ function stayExpense(linked: Reservation[], budget: DayContentBudget | undefined
|
||||
*/
|
||||
export function contentOnDays(days: Pick<Day, 'id' | 'title' | 'notes'>[], data: DayContentData): DayContent {
|
||||
const ids = new Set(days.map(d => d.id))
|
||||
const stays = data.accommodations.filter(stay => ids.has(stay.start_day_id) || ids.has(stay.end_day_id))
|
||||
const stays = distinctStays(data.accommodations).filter(stay => ids.has(stay.start_day_id) || ids.has(stay.end_day_id))
|
||||
const stayIds = new Set(stays.map(stay => stay.id))
|
||||
|
||||
const placeIds = new Set<number>()
|
||||
@@ -188,7 +198,7 @@ export function dayDeleteImpact(
|
||||
return start || end
|
||||
}).length
|
||||
|
||||
const shortenedStays = data.accommodations.flatMap((stay): ShortenedStay[] => {
|
||||
const shortenedStays = distinctStays(data.accommodations).flatMap((stay): ShortenedStay[] => {
|
||||
const from = position.get(stay.start_day_id)
|
||||
const to = position.get(stay.end_day_id)
|
||||
if (cancelled.has(stay.id) || from === undefined || to === undefined || from >= at || to <= at) return []
|
||||
|
||||
@@ -13,11 +13,18 @@ type Translate = (key: string, params?: Record<string, string | number>) => stri
|
||||
*/
|
||||
export function dayLabel(day: Pick<Day, 'title' | 'date'>, index: number, t: Translate, locale: string): string {
|
||||
if (day.title) return day.title
|
||||
if (day.date) {
|
||||
const date = new Date(`${day.date.slice(0, 10)}T00:00:00`)
|
||||
if (!Number.isNaN(date.getTime())) {
|
||||
return date.toLocaleDateString(locale, { weekday: 'short', day: 'numeric', month: 'short' })
|
||||
}
|
||||
}
|
||||
return t('dayplan.dayN', { n: index + 1 })
|
||||
return (day.date && dayDate(day.date, locale)) || t('dayplan.dayN', { n: index + 1 })
|
||||
}
|
||||
|
||||
/**
|
||||
* A calendar date the way the day list writes it: short weekday, day, month,
|
||||
* and no year, which the trip around it already says. Anything that talks
|
||||
* about the days in that list (the next day to add, a moved check-out, the new
|
||||
* end of the trip) writes its dates this way too, so a date reads the same in
|
||||
* the button as in the row it becomes. Null when the value does not parse.
|
||||
*/
|
||||
export function dayDate(iso: string, locale: string): string | null {
|
||||
const date = new Date(`${iso.slice(0, 10)}T00:00:00`)
|
||||
if (Number.isNaN(date.getTime())) return null
|
||||
return date.toLocaleDateString(locale, { weekday: 'short', day: 'numeric', month: 'short' })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user