From 5644e3d77e1153b3790011a16d2e6aff9829e09b Mon Sep 17 00:00:00 2001 From: Maurice Date: Fri, 9 Oct 2026 17:39:14 +0200 Subject: [PATCH] fix(vacay): the desktop calendar no longer requests the trips again on every vacay refresh Every vacay refresh on desktop (opening the page, a vacay:settings or vacay:invite update from another member) sent a second GET /trips just to redraw the same trip dots, even when the leave-year window had not changed. Cause: useVacayCalendarLogic keyed the trip dot reload on the year settings object when tripsFollowWindowShape was false (the desktop grid). loadAll() replaces that object with a deep-equal copy on every refresh, so the effect ran again. The phone screen already keyed it on the window shape. Fix: the trip dots always reload on the window shape (year type, start month, start day, hire date), which covers every field the dot filter reads. The option only existed to keep the desktop behaviour, so it is removed from the hook and from both callers. Red test: FE-COMP-VACAYCAL-010 (useVacayCalendarLogic.test.ts) failed on the unfixed code with "AssertionError: expected "list" to be called 1 times, but got 2 times". Changed assertions: - useVacayCalendarLogic.test.ts FE-COMP-VACAYCAL-010: was "the desktop mode reloads trips on every new settings object" expecting tripsApi.list to be called 2 times after a deep-equal settings replacement; now expects 1. - FE-COMP-VACAYCAL-011 no longer passes tripsFollowWindowShape and no longer names the phone mode; its assertions are unchanged. --- client/src/components/Vacay/VacayCalendar.tsx | 2 +- .../components/Vacay/useVacayCalendarLogic.test.ts | 13 +++++++------ .../src/components/Vacay/useVacayCalendarLogic.ts | 12 +++++------- client/src/mobile/screens/vacay/useMVacay.ts | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/client/src/components/Vacay/VacayCalendar.tsx b/client/src/components/Vacay/VacayCalendar.tsx index ab66740fd..e696e037f 100644 --- a/client/src/components/Vacay/VacayCalendar.tsx +++ b/client/src/components/Vacay/VacayCalendar.tsx @@ -15,7 +15,7 @@ export default function VacayCalendar() { mode, setMode, halfDay, setHalfDay, compDay, setCompDay, tripDates, entryMap, sharedMap, companyHolidaySet, companyHalfSet, blockWeekends, weekendDays, companyHolidaysEnabled, selectedUser, logDay: handleCellClick, - } = useVacayCalendarLogic({ selectedYear, plan, tripsFollowWindowShape: false }) + } = useVacayCalendarLogic({ selectedYear, plan }) const companyMode = mode === 'company' const [tip, setTip] = useState(null) diff --git a/client/src/components/Vacay/useVacayCalendarLogic.test.ts b/client/src/components/Vacay/useVacayCalendarLogic.test.ts index 140d5f71d..7f3397b36 100644 --- a/client/src/components/Vacay/useVacayCalendarLogic.test.ts +++ b/client/src/components/Vacay/useVacayCalendarLogic.test.ts @@ -33,7 +33,7 @@ function entry(over: Partial): VacayEntry { type Options = Parameters[0]; function logic(over: Partial = {}) { - const props: Options = { selectedYear: 2026, plan: plan(), tripsFollowWindowShape: false, ...over }; + const props: Options = { selectedYear: 2026, plan: plan(), ...over }; return renderHook((p: Options) => useVacayCalendarLogic(p), { initialProps: props }); } @@ -79,7 +79,7 @@ describe('useVacayCalendarLogic', () => { await act(() => result.current.logDay('2026-03-04')); expect(toggleCompanyHoliday).toHaveBeenCalledWith('2026-03-04', 0.5); - rerender({ selectedYear: 2026, plan: plan({ company_holidays_enabled: false }), tripsFollowWindowShape: false }); + rerender({ selectedYear: 2026, plan: plan({ company_holidays_enabled: false }) }); await act(() => result.current.logDay('2026-03-05')); expect(toggleCompanyHoliday).toHaveBeenCalledTimes(1); expect(result.current.companyHolidaysEnabled).toBe(false); @@ -160,17 +160,18 @@ describe('useVacayCalendarLogic', () => { expect([...result.current.tripDates]).toEqual(['2026-01-01', '2026-01-02']); }); - it('FE-COMP-VACAYCAL-010: the desktop mode reloads trips on every new settings object', async () => { + it('FE-COMP-VACAYCAL-010: the desktop grid does not request the trips again for a deep-equal settings reload', async () => { const list = vi.spyOn(tripsApi, 'list').mockResolvedValue({ trips: [] } as never); logic(); await waitFor(() => expect(list).toHaveBeenCalledTimes(1)); act(() => useVacayStore.setState({ yearSettings: { ...CALENDAR } })); - await waitFor(() => expect(list).toHaveBeenCalledTimes(2)); + await act(async () => {}); + expect(list).toHaveBeenCalledTimes(1); }); - it('FE-COMP-VACAYCAL-011: the phone mode reloads trips only when the window shape changes', async () => { + it('FE-COMP-VACAYCAL-011: the trips reload only when the window shape changes', async () => { const list = vi.spyOn(tripsApi, 'list').mockResolvedValue({ trips: [] } as never); - logic({ tripsFollowWindowShape: true }); + logic(); await waitFor(() => expect(list).toHaveBeenCalledTimes(1)); act(() => useVacayStore.setState({ yearSettings: { ...CALENDAR } })); await Promise.resolve(); diff --git a/client/src/components/Vacay/useVacayCalendarLogic.ts b/client/src/components/Vacay/useVacayCalendarLogic.ts index 210d57f4c..f287c79f0 100644 --- a/client/src/components/Vacay/useVacayCalendarLogic.ts +++ b/client/src/components/Vacay/useVacayCalendarLogic.ts @@ -20,11 +20,6 @@ type SharedDayMark = { interface VacayCalendarLogicOptions { selectedYear: number; plan: VacayPlan | null | undefined; - /** - * Reload the trip dots only when the leave-year window changes shape (the phone - * screen). Otherwise they reload whenever the settings object is replaced. - */ - tripsFollowWindowShape: boolean; } /** The leave-year window's shape as a primitive, stable across deep-equal reloads. */ @@ -41,7 +36,7 @@ function localDay(d: Date): string { * screen: the log mode with its half-day and comp-day modifiers, the per-day maps * the cells render from, the trip dots, and what a click on a day logs. */ -export function useVacayCalendarLogic({ selectedYear, plan, tripsFollowWindowShape }: VacayCalendarLogicOptions) { +export function useVacayCalendarLogic({ selectedYear, plan }: VacayCalendarLogicOptions) { const selectedUserId = useVacayStore((s) => s.selectedUserId); const entries = useVacayStore((s) => s.entries); const companyHolidays = useVacayStore((s) => s.companyHolidays); @@ -60,7 +55,10 @@ export function useVacayCalendarLogic({ selectedYear, plan, tripsFollowWindowSha const [compDay, setCompDay] = useState(false); const [tripDates, setTripDates] = useState>(new Set()); - const tripsKey = tripsFollowWindowShape ? vacayWindowShape(yearSettings) : yearSettings; + // The trip dots reload only when the leave-year window changes shape: loadAll() + // hands back a deep-equal settings object on every refresh, and that must not + // request the trips again. + const tripsKey = vacayWindowShape(yearSettings); useEffect(() => { const settings = useVacayStore.getState().yearSettings; let cancelled = false; diff --git a/client/src/mobile/screens/vacay/useMVacay.ts b/client/src/mobile/screens/vacay/useMVacay.ts index 7cbf8ab2e..73532a57a 100644 --- a/client/src/mobile/screens/vacay/useMVacay.ts +++ b/client/src/mobile/screens/vacay/useMVacay.ts @@ -46,7 +46,7 @@ export function useMVacay() { const { mode, setMode, halfDay, setHalfDay, compDay, setCompDay, tripDates, entryMap, sharedMap, companyHolidaySet, companyHalfSet, blockWeekends, weekendDays, companyHolidaysEnabled, logDay, - } = useVacayCalendarLogic({ selectedYear, plan, tripsFollowWindowShape: true }) + } = useVacayCalendarLogic({ selectedYear, plan }) const [sheet, setSheet] = useState(null) // The leave-year window's shape as a primitive. loadAll() hands back a fresh