Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(vacay): the desktop calendar no longer requests the trips again on every vacay refresh

Maurice5644e3d77e11
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<HoverTip | null>(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>): 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();
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<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;
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<MVacaySheet>(null)
// The leave-year window's shape as a primitive. loadAll() hands back a fresh