mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 11:36:05 +00:00
cc94bc6953
The day badge fix grew DayPlanSidebar.tsx and its test past their size baselines. The check-out, through, check-in order of the header's stays is now dayHeadStays() with a test of its own, and the day header tests sit in DayPlanSidebar.dayHead.test.tsx; both files drop below their old entries.
19 lines
737 B
TypeScript
19 lines
737 B
TypeScript
import type { Accommodation, Day } from '../../types';
|
|
import { isDayInAccommodationRange } from '../../utils/dayOrder';
|
|
|
|
/**
|
|
* The stays a day's header names, in the order a traveller meets them that day:
|
|
* the one checked out of first, then the ones running through, the one checked
|
|
* into last.
|
|
*/
|
|
export function dayHeadStays(accommodations: Accommodation[], day: Day, days: Day[]): Accommodation[] {
|
|
const rank = (a: Accommodation) => {
|
|
if (a.end_day_id === day.id && a.start_day_id !== day.id) return 0;
|
|
if (a.start_day_id === day.id) return 2;
|
|
return 1;
|
|
};
|
|
return accommodations
|
|
.filter((a) => isDayInAccommodationRange(day, a.start_day_id, a.end_day_id, days))
|
|
.sort((a, b) => rank(a) - rank(b));
|
|
}
|