diff --git a/components/pages/calendar/useFormattedEvents.ts b/components/pages/calendar/useFormattedEvents.ts index d61ea74..65597f8 100644 --- a/components/pages/calendar/useFormattedEvents.ts +++ b/components/pages/calendar/useFormattedEvents.ts @@ -31,7 +31,7 @@ interface FormattedEvent { // Precompute time constants const DAY_IN_MS = 24 * 60 * 60 * 1000; -const PERIOD_IN_MS = 45 * DAY_IN_MS; +const PERIOD_IN_MS = 5 * DAY_IN_MS; const TIME_ZONE = Intl.DateTimeFormat().resolvedOptions().timeZone; // Memoize date range calculations diff --git a/hooks/firebase/useGetHouseholdName.ts b/hooks/firebase/useGetHouseholdName.ts index cbcaafc..f9849eb 100644 --- a/hooks/firebase/useGetHouseholdName.ts +++ b/hooks/firebase/useGetHouseholdName.ts @@ -2,35 +2,29 @@ import { useQuery } from "@tanstack/react-query"; import firestore from "@react-native-firebase/firestore"; export const useGetHouseholdName = (familyId: string) => { - return useQuery( - ["getHouseholdName", familyId], // Unique query key - async () => { - console.log(`Fetching household name for familyId: ${familyId}`); - + return useQuery({ + queryKey: ["household", familyId], + queryFn: async () => { try { - // Query the Households collection for the given familyId const snapshot = await firestore() - .collection("Households") - .where("familyId", "==", familyId) - .get(); + .collection("Households") + .where("familyId", "==", familyId) + .get(); if (!snapshot.empty) { - // Extract the name from the first matching document const householdData = snapshot.docs[0].data(); console.log("Household found:", householdData); - return householdData.name || null; // Return the name or null if missing - } else { - console.log("No household found for the given familyId."); - return null; // Return null if no household found + return householdData.name ?? null; } + + console.log("No household found for the given familyId."); + return null; } catch (e) { console.error("Error fetching household name:", e); - throw e; // Ensure error propagates to the query error handling + throw e; } }, - { - enabled: !!familyId, // Only fetch if familyId is provided - staleTime: 5 * 60 * 1000, // Cache the data for 5 minutes - } - ); -}; + enabled: Boolean(familyId), + staleTime: 5 * 60 * 1000, + }); +}; \ No newline at end of file