From 413164128b37d3eb012d0dfb2d30cb93b92c4f90 Mon Sep 17 00:00:00 2001 From: Dejan Date: Fri, 17 Jan 2025 02:00:36 +0100 Subject: [PATCH 1/3] - Fixed events fetching in family view because there are events that don't have the private field - Implemented marking events as private --- .../pages/calendar/ManuallyAddEventModal.tsx | 14 +++++--------- hooks/firebase/types/eventData.ts | 3 ++- hooks/firebase/useGetEvents.ts | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/components/pages/calendar/ManuallyAddEventModal.tsx b/components/pages/calendar/ManuallyAddEventModal.tsx index a8c4ece..5ebe038 100644 --- a/components/pages/calendar/ManuallyAddEventModal.tsx +++ b/components/pages/calendar/ManuallyAddEventModal.tsx @@ -2,7 +2,8 @@ import { Button, ButtonSize, Colors, - DateTimePicker, Dialog, + DateTimePicker, + Dialog, LoaderScreen, Modal, Picker, @@ -21,7 +22,6 @@ import {AntDesign, Feather, Ionicons} from "@expo/vector-icons"; import {PickerMultiValue} from "react-native-ui-lib/src/components/picker/types"; import {useCreateEvent} from "@/hooks/firebase/useCreateEvent"; import {EventData} from "@/hooks/firebase/types/eventData"; -import DropModalIcon from "@/assets/svgs/DropModalIcon"; import {Alert, StyleSheet} from "react-native"; import ClockIcon from "@/assets/svgs/ClockIcon"; import LockIcon from "@/assets/svgs/LockIcon"; @@ -29,17 +29,12 @@ import MenuIcon from "@/assets/svgs/MenuIcon"; import CameraIcon from "@/assets/svgs/CameraIcon"; import AssigneesDisplay from "@/components/shared/AssigneesDisplay"; import {useAtom} from "jotai"; -import { - eventForEditAtom, - selectedNewEventDateAtom, - isAllDayAtom, -} from "@/components/pages/calendar/atoms"; +import {eventForEditAtom, isAllDayAtom, selectedNewEventDateAtom,} from "@/components/pages/calendar/atoms"; import {useGetFamilyMembers} from "@/hooks/firebase/useGetFamilyMembers"; -import BinIcon from "@/assets/svgs/BinIcon"; import DeleteEventDialog from "./DeleteEventDialog"; import {useDeleteEvent} from "@/hooks/firebase/useDeleteEvent"; import AddPersonIcon from "@/assets/svgs/AddPersonIcon"; -import {addHours, format, startOfHour, startOfMinute} from "date-fns"; +import {addHours, format, startOfMinute} from "date-fns"; import {ProfileType, useAuthContext} from "@/contexts/AuthContext"; import {Calendar} from "react-native-calendars"; @@ -233,6 +228,7 @@ export const ManuallyAddEventModal = () => { attendees: selectedAttendees, notes: details, location: location, + private: isPrivate }; if (editEvent?.id) eventData.id = editEvent?.id; diff --git a/hooks/firebase/types/eventData.ts b/hooks/firebase/types/eventData.ts index 9f3a3df..ed7d5f0 100644 --- a/hooks/firebase/types/eventData.ts +++ b/hooks/firebase/types/eventData.ts @@ -12,5 +12,6 @@ export interface EventData { reminders?: string[] id?: string | number, attendees?: string[], - location?: string + location?: string, + private?: boolean } \ No newline at end of file diff --git a/hooks/firebase/useGetEvents.ts b/hooks/firebase/useGetEvents.ts index fe90172..9ee8c74 100644 --- a/hooks/firebase/useGetEvents.ts +++ b/hooks/firebase/useGetEvents.ts @@ -29,7 +29,7 @@ const fetchEvents = async (userId: string, profileData: UserProfile | undefined, if (isFamilyView || profileData?.userType === ProfileType.FAMILY_DEVICE) { constraints = [ - eventsQuery.where("familyId", "==", familyId).where("private", "==", false), + eventsQuery.where("familyId", "==", familyId).where("private", "not-in", [true]), eventsQuery.where("creatorId", "==", userId), eventsQuery.where("attendees", "array-contains", userId) ]; From dcca6520196945cf51e871374c20ff2ac611e6a6 Mon Sep 17 00:00:00 2001 From: Dejan Date: Sat, 18 Jan 2025 00:31:48 +0100 Subject: [PATCH 2/3] - Improved fetching of events for family device - Removed fetching events and considering if they're private or not --- hooks/firebase/useGetEvents.ts | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/hooks/firebase/useGetEvents.ts b/hooks/firebase/useGetEvents.ts index 9ee8c74..f40fd1b 100644 --- a/hooks/firebase/useGetEvents.ts +++ b/hooks/firebase/useGetEvents.ts @@ -27,17 +27,23 @@ const fetchEvents = async (userId: string, profileData: UserProfile | undefined, let constraints; let familyId = profileData?.familyId; - if (isFamilyView || profileData?.userType === ProfileType.FAMILY_DEVICE) { + if (profileData?.userType === ProfileType.FAMILY_DEVICE) { constraints = [ - eventsQuery.where("familyId", "==", familyId).where("private", "not-in", [true]), - eventsQuery.where("creatorId", "==", userId), - eventsQuery.where("attendees", "array-contains", userId) + eventsQuery.where("familyId", "==", familyId) ]; } else { - constraints = [ - eventsQuery.where("creatorId", "==", userId), - eventsQuery.where("attendees", "array-contains", userId) - ]; + if (isFamilyView) { + constraints = [ + eventsQuery.where("familyId", "==", familyId), + eventsQuery.where("creatorId", "==", userId), + eventsQuery.where("attendees", "array-contains", userId) + ]; + } else { + constraints = [ + eventsQuery.where("creatorId", "==", userId), + eventsQuery.where("attendees", "array-contains", userId) + ]; + } } const snapshots = await Promise.all(constraints.map(query => query.get())); @@ -49,6 +55,7 @@ const fetchEvents = async (userId: string, profileData: UserProfile | undefined, snapshots.forEach(snapshot => { snapshot.docs.forEach(doc => { const event = doc.data(); + console.log(event); const hash = createEventHash(event); if (!processedHashes.has(hash)) { @@ -102,13 +109,13 @@ export const useGetEvents = () => { await queryClient.prefetchQuery({ queryKey: ["events", user.uid, false], // Personal events queryFn: () => fetchEvents(user.uid, profileData, false), - staleTime: 5 * 60 * 1000, + staleTime: 1000, }); await queryClient.prefetchQuery({ queryKey: ["events", user.uid, true], // Family events queryFn: () => fetchEvents(user.uid, profileData, true), - staleTime: 5 * 60 * 1000, + staleTime:1000, }); }; From 5333b8cbb76cc7e20c7956843223e9101394b7ad Mon Sep 17 00:00:00 2001 From: Dejan Date: Sat, 18 Jan 2025 00:33:10 +0100 Subject: [PATCH 3/3] - Reverted the stale time --- hooks/firebase/useGetEvents.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hooks/firebase/useGetEvents.ts b/hooks/firebase/useGetEvents.ts index f40fd1b..e5147fd 100644 --- a/hooks/firebase/useGetEvents.ts +++ b/hooks/firebase/useGetEvents.ts @@ -55,7 +55,6 @@ const fetchEvents = async (userId: string, profileData: UserProfile | undefined, snapshots.forEach(snapshot => { snapshot.docs.forEach(doc => { const event = doc.data(); - console.log(event); const hash = createEventHash(event); if (!processedHashes.has(hash)) { @@ -109,13 +108,13 @@ export const useGetEvents = () => { await queryClient.prefetchQuery({ queryKey: ["events", user.uid, false], // Personal events queryFn: () => fetchEvents(user.uid, profileData, false), - staleTime: 1000, + staleTime: 5 * 60 * 1000, }); await queryClient.prefetchQuery({ queryKey: ["events", user.uid, true], // Family events queryFn: () => fetchEvents(user.uid, profileData, true), - staleTime:1000, + staleTime: 5 * 60 * 1000, }); };