From bbd66e49f264e95694fd918e2bad0ff322859973 Mon Sep 17 00:00:00 2001 From: dev_agent Date: Thu, 8 Oct 2026 21:04:16 -0400 Subject: [PATCH] Share the Draft board's swap step with Add to this week useWeekSwap is now the one way a day is swapped: it refuses while a swap or push of the week is pending, and leaves the week's settled swaps and pushes behind before sending the swap. The Draft board (sheet, drop and retry) and the dinner's Add to this week sheet and its Retry all use it, so a swap from the dinner no longer leaves the Plan saying the earlier plan's Supply run was made. Co-Authored-By: Claude Opus 5.5 --- web/src/dinners/AddToWeekSheet.tsx | 19 ++--- web/src/dinners/DinnerDetailActions.test.tsx | 75 ++++++++++++++++++-- web/src/dinners/DinnerDetailPage.tsx | 13 ++-- web/src/plan/PlanPage.tsx | 29 +++----- web/src/plan/api.ts | 31 ++++++++ 5 files changed, 130 insertions(+), 37 deletions(-) diff --git a/web/src/dinners/AddToWeekSheet.tsx b/web/src/dinners/AddToWeekSheet.tsx index f656e30..0998ae2 100644 --- a/web/src/dinners/AddToWeekSheet.tsx +++ b/web/src/dinners/AddToWeekSheet.tsx @@ -1,6 +1,6 @@ import { useId, useState } from 'react' import { Link } from 'react-router' -import { usePlan, useSwapDay, type PlanDinner, type Swap } from '../plan/api.ts' +import { usePlan, useWeekSwap, type PlanDinner, type Swap } from '../plan/api.ts' import { cooking } from '../plan/PlanPage.tsx' import swapStyles from '../plan/SwapSheet.module.css' import { addDays, dayOfMonth, localNow, weekdayName, weekLabel, weekStart as weekOf } from '../plan/week.ts' @@ -41,13 +41,14 @@ type WeekDaysProps = { } // WeekDays is the seven days of the week starting on week, each with its -// dinner; choosing one swaps the dinner in through the Plan's own swap -// (useSwapDay). A week with no plan offers to draft it on the Draft board: +// dinner; choosing one swaps the dinner in as the Draft board swaps a day +// (useWeekSwap). A week with no plan offers to draft it on the Draft board: // nothing here makes a plan up. A dinner already on the week can't be added -// again, nor can one while a change to the week is still being saved. +// again, nor can one while a swap of the week is still being saved or the +// week is being pushed to Calendar. function WeekDays({ dinner, week, which, onAdd }: WeekDaysProps) { const plan = usePlan(week) - const swap = useSwapDay(week) + const { swap, push, refused, swapIn } = useWeekSwap(week) if (plan.isError) { return void plan.refetch()}>Couldn't load {weekNames[which]}'s plan. {plan.error.message} @@ -74,10 +75,10 @@ function WeekDays({ dinner, week, which, onAdd }: WeekDaysProps) { const days = plan.data.days const planned = days.find((day) => day.dinner.id === dinner.id) - const choosable = planned === undefined && !swap.pending + const choosable = planned === undefined && !refused function add(date: string) { const chosen: Swap = { date, dinner: planDinner(dinner), fromQuestLog: dinner.status === 'quest_log' } - swap.mutate(chosen) + swapIn(chosen) onAdd({ week, which, swap: chosen }) } return ( @@ -86,8 +87,10 @@ function WeekDays({ dinner, week, which, onAdd }: WeekDaysProps) {

{dinner.name} is already on {weekdayName(planned.date)} {weekNames[which]}.

+ ) : swap.pending ? ( +

A change to {weekNames[which]} is still being saved.

) : ( - swap.pending &&

A change to {weekNames[which]} is still being saved.

+ push.pending &&

The plan for {weekNames[which]} is being pushed to Calendar.

)}