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.
This commit is contained in:
Maurice
2026-10-09 17:39:14 +02:00
parent 694e11c117
commit 5644e3d77e
4 changed files with 14 additions and 15 deletions
@@ -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<HoverTip | null>(null)
@@ -33,7 +33,7 @@ function entry(over: Partial<VacayEntry>): VacayEntry {
type Options = Parameters<typeof useVacayCalendarLogic>[0];
function logic(over: Partial<Options> = {}) {
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();
@@ -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<Set<string>>(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;
+1 -1
View File
@@ -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<MVacaySheet>(null)
// The leave-year window's shape as a primitive. loadAll() hands back a fresh