feat(planner): add sortEasiestFirst utility for J4 swap context

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-09 10:03:47 +02:00
parent dac83c70ea
commit 8756bf93d9
2 changed files with 70 additions and 1 deletions

View File

@@ -75,6 +75,25 @@ export function isToday(dateStr: string): boolean {
return dateStr === todayStr;
}
const EFFORT_ORDER: Record<string, number> = { easy: 0, medium: 1, hard: 2 };
/**
* Returns a new array of recipes sorted easiest first (effort ASC, cookTimeMin ASC).
* Used for the J4 mid-week swap context — different from variety-first sorting in J2.
*/
export function sortEasiestFirst<T extends { effort?: string | null; cookTimeMin?: number | null }>(
recipes: T[]
): T[] {
return [...recipes].sort((a, b) => {
const ea = a.effort != null ? (EFFORT_ORDER[a.effort] ?? 99) : 99;
const eb = b.effort != null ? (EFFORT_ORDER[b.effort] ?? 99) : 99;
if (ea !== eb) return ea - eb;
const ta = a.cookTimeMin ?? Infinity;
const tb = b.cookTimeMin ?? Infinity;
return ta - tb;
});
}
/**
* Formats a week range: "30. Mär 5. Apr 2026".
*/