diff --git a/babel.config.js b/babel.config.js index 0fde861..ab04247 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,8 +1,10 @@ module.exports = function (api) { + const env = process.env.NODE_ENV; api.cache(true); - let plugins = [] - if (babelEnv !== 'development') { + let plugins = []; + + if (env !== 'development') { plugins.push('transform-remove-console'); } @@ -12,4 +14,4 @@ module.exports = function (api) { ], plugins }; -}; +}; \ No newline at end of file diff --git a/contexts/AuthContext.tsx b/contexts/AuthContext.tsx index b89be2c..6dff1c3 100644 --- a/contexts/AuthContext.tsx +++ b/contexts/AuthContext.tsx @@ -166,7 +166,7 @@ export const AuthContextProvider: FC<{ children: ReactNode }> = ({children}) => useEffect(() => { const handleNotification = async (notification: Notifications.Notification) => { - queryClient.invalidateQueries(["notifications"]); + queryClient.invalidateQueries({queryKey: ["notifications"]}); }; const sub = Notifications.addNotificationReceivedListener(handleNotification); diff --git a/hooks/firebase/useChangeProfilePicture.ts b/hooks/firebase/useChangeProfilePicture.ts index ad2ceed..cbd483b 100644 --- a/hooks/firebase/useChangeProfilePicture.ts +++ b/hooks/firebase/useChangeProfilePicture.ts @@ -53,7 +53,7 @@ export const useChangeProfilePicture = (customUserId?: string) => { onSuccess: () => { // Invalidate queries to refresh profile data if (!customUserId) { - queryClient.invalidateQueries("Profiles"); + queryClient.invalidateQueries({queryKey: ["Profiles"]}); refreshProfileData(); } }, diff --git a/hooks/firebase/useCreateEvent.ts b/hooks/firebase/useCreateEvent.ts index 35096a5..ebbbcde 100644 --- a/hooks/firebase/useCreateEvent.ts +++ b/hooks/firebase/useCreateEvent.ts @@ -83,7 +83,7 @@ export const useCreateEventsFromProvider = () => { } }, onSuccess: () => { - queryClient.invalidateQueries("events"); + queryClient.invalidateQueries({queryKey: ["events"]}); } }); }; \ No newline at end of file diff --git a/hooks/firebase/useCreateFeedback.ts b/hooks/firebase/useCreateFeedback.ts index 0664937..9a03b37 100644 --- a/hooks/firebase/useCreateFeedback.ts +++ b/hooks/firebase/useCreateFeedback.ts @@ -1,47 +1,44 @@ -import {useAuthContext} from "@/contexts/AuthContext"; -import {useMutation, useQueryClient} from "@tanstack/react-query"; +import { useAuthContext } from "@/contexts/AuthContext"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; import firestore from "@react-native-firebase/firestore"; import { IFeedback } from "@/contexts/FeedbackContext"; export const useCreateFeedback = () => { - const {user: currentUser, profileData} = useAuthContext() - const queryClients = useQueryClient() + const { user: currentUser } = useAuthContext(); + const queryClient = useQueryClient(); return useMutation({ mutationKey: ["createFeedback"], mutationFn: async (feedback: Partial) => { - try { - if (feedback.id) { - const snapshot = await firestore() - .collection("Feedbacks") - .where("id", "==", feedback.id) - .get(); - - if (!snapshot.empty) { - const docId = snapshot.docs[0].id; - await firestore() - .collection("Feedbacks") - .doc(docId) - .set({ - ...feedback, - creatorId: currentUser?.uid, - }, {merge: true}); - return; - } - } - const newDoc = firestore().collection('Feedbacks').doc(); - await firestore() + if (feedback.id) { + const snapshot = await firestore() .collection("Feedbacks") - .add({...feedback, id: newDoc.id, creatorId: currentUser?.uid}); - } catch (e) { - console.error(e); + .where("id", "==", feedback.id) + .get(); + + if (!snapshot.empty) { + const docId = snapshot.docs[0].id; + await firestore() + .collection("Feedbacks") + .doc(docId) + .set({ + ...feedback, + creatorId: currentUser?.uid, + }, { merge: true }); + return; + } } + + const newDoc = firestore().collection('Feedbacks').doc(); + await firestore() + .collection("Feedbacks") + .add({ ...feedback, id: newDoc.id, creatorId: currentUser?.uid }); }, onSuccess: () => { - queryClients.invalidateQueries("feedbacks") + queryClient.invalidateQueries({ queryKey: ["feedbacks"] }); } - }) -} + }); +}; export const useCreateFeedbacksFromProvider = () => { const { user: currentUser } = useAuthContext(); @@ -50,36 +47,29 @@ export const useCreateFeedbacksFromProvider = () => { return useMutation({ mutationKey: ["createFeedbacksFromProvider"], mutationFn: async (feedbackDataArray: Partial[]) => { - try { - const promises = feedbackDataArray.map(async (feedbackData) => { - console.log("Processing FeedbackData: ", feedbackData); + const promises = feedbackDataArray.map(async (feedbackData) => { + const snapshot = await firestore() + .collection("Feedbacks") + .where("id", "==", feedbackData.id) + .get(); - const snapshot = await firestore() + if (snapshot.empty) { + return firestore() .collection("Feedbacks") - .where("id", "==", feedbackData.id) - .get(); + .add({ ...feedbackData, creatorId: currentUser?.uid }); + } - if (snapshot.empty) { - return firestore() - .collection("Feedbacks") - .add({ ...feedbackData, creatorId: currentUser?.uid }); - } else { - const docId = snapshot.docs[0].id; - return firestore() - .collection("Feedbacks") - .doc(docId) - .set({ ...feedbackData, creatorId: currentUser?.uid }, { merge: true }); - } - }); + const docId = snapshot.docs[0].id; + return firestore() + .collection("Feedbacks") + .doc(docId) + .set({ ...feedbackData, creatorId: currentUser?.uid }, { merge: true }); + }); - await Promise.all(promises); - - } catch (e) { - console.error("Error creating/updating feedbacks: ", e); - } + await Promise.all(promises); }, onSuccess: () => { - queryClient.invalidateQueries("feedbacks"); + queryClient.invalidateQueries({ queryKey: ["feedbacks"] }); } }); }; \ No newline at end of file diff --git a/hooks/firebase/useCreateGrocery.ts b/hooks/firebase/useCreateGrocery.ts index 090bc8e..624e36b 100644 --- a/hooks/firebase/useCreateGrocery.ts +++ b/hooks/firebase/useCreateGrocery.ts @@ -1,26 +1,30 @@ import { useMutation, useQueryClient } from "@tanstack/react-query"; import firestore from "@react-native-firebase/firestore"; import { useAuthContext } from "@/contexts/AuthContext"; -import {IGrocery} from "@/hooks/firebase/types/groceryData"; +import { IGrocery } from "@/hooks/firebase/types/groceryData"; export const useCreateGrocery = () => { const { user: currentUser, profileData } = useAuthContext(); - const queryClients = useQueryClient(); + const queryClient = useQueryClient(); + const groceriesKey = ["groceries"]; return useMutation({ - mutationKey: ["createGrocery"], - mutationFn: async (groceryData: Partial) => { - try { - const newDoc = firestore().collection('Groceries').doc(); - await firestore() - .collection("Groceries") - .add({...groceryData, id: newDoc.id, familyId: profileData?.familyId, creatorId: currentUser?.uid}) - } catch (e) { - console.error(e) - } + mutationFn: (groceryData: Partial) => { + const newDoc = firestore().collection('Groceries').doc(); + return firestore() + .collection("Groceries") + .add({ + ...groceryData, + id: newDoc.id, + familyId: profileData?.familyId, + creatorId: currentUser?.uid + }); }, onSuccess: () => { - queryClients.invalidateQueries("groceries") + return queryClient.invalidateQueries({ + queryKey: groceriesKey, + exact: true + }); } - }) -} \ No newline at end of file + }); +}; \ No newline at end of file diff --git a/hooks/firebase/useCreateNote.ts b/hooks/firebase/useCreateNote.ts index 2244f4e..d124a6b 100644 --- a/hooks/firebase/useCreateNote.ts +++ b/hooks/firebase/useCreateNote.ts @@ -42,7 +42,7 @@ export const useCreateNote = () => { } }, onSuccess: () => { - queryClients.invalidateQueries("braindumps"); + queryClients.invalidateQueries({queryKey: ["braindumps"]}); }, }); }; @@ -85,7 +85,7 @@ export const useCreateNotesFromProvider = () => { } }, onSuccess: () => { - queryClient.invalidateQueries("braindumps"); + queryClient.invalidateQueries({queryKey: ["braindumps"]}); }, }); }; diff --git a/hooks/firebase/useCreateTodo.ts b/hooks/firebase/useCreateTodo.ts index 92b5a06..716203b 100644 --- a/hooks/firebase/useCreateTodo.ts +++ b/hooks/firebase/useCreateTodo.ts @@ -140,7 +140,7 @@ export const useCreateTodo = () => { } }, onSuccess: () => { - queryClients.invalidateQueries("todos") + queryClients.invalidateQueries({queryKey: ["todos"]}) } }) } diff --git a/hooks/firebase/useDeleteEvent.ts b/hooks/firebase/useDeleteEvent.ts index 1cd10cc..9d8c83c 100644 --- a/hooks/firebase/useDeleteEvent.ts +++ b/hooks/firebase/useDeleteEvent.ts @@ -33,7 +33,7 @@ export const useDeleteEvent = () => { } }, onSuccess: () => { - queryClient.invalidateQueries("events"); + queryClient.invalidateQueries({queryKey: ["events"]}); } }); }; \ No newline at end of file diff --git a/hooks/firebase/useDeleteFeedback.ts b/hooks/firebase/useDeleteFeedback.ts index 69f4c32..12f6141 100644 --- a/hooks/firebase/useDeleteFeedback.ts +++ b/hooks/firebase/useDeleteFeedback.ts @@ -39,7 +39,7 @@ export const useDeleteFeedback = () => { } }, onSuccess: () => { - queryClient.invalidateQueries("feedbacks"); + queryClient.invalidateQueries({queryKey: ["feedbacks"]}); }, }); }; diff --git a/hooks/firebase/useDeleteGrocery.ts b/hooks/firebase/useDeleteGrocery.ts index 0e2e882..56bb161 100644 --- a/hooks/firebase/useDeleteGrocery.ts +++ b/hooks/firebase/useDeleteGrocery.ts @@ -15,7 +15,7 @@ export const useDeleteGrocery = () => { } }, onSuccess: () => { - queryClient.invalidateQueries("groceries"); + queryClient.invalidateQueries({queryKey: ["groceries"]}); }, }); }; diff --git a/hooks/firebase/useDeleteNote.ts b/hooks/firebase/useDeleteNote.ts index 752ca27..36bc93c 100644 --- a/hooks/firebase/useDeleteNote.ts +++ b/hooks/firebase/useDeleteNote.ts @@ -33,7 +33,7 @@ export const useDeleteNote = () => { } }, onSuccess: () => { - queryClient.invalidateQueries("braindumps"); + queryClient.invalidateQueries({queryKey: ["braindumps"]}); }, }); }; diff --git a/hooks/firebase/useDeleteNotification.ts b/hooks/firebase/useDeleteNotification.ts index 7c7296b..0a363fb 100644 --- a/hooks/firebase/useDeleteNotification.ts +++ b/hooks/firebase/useDeleteNotification.ts @@ -1,11 +1,12 @@ -import {useMutation, useQueryClient} from "@tanstack/react-query"; -import {useAuthContext} from "@/contexts/AuthContext"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { useAuthContext } from "@/contexts/AuthContext"; import firestore from "@react-native-firebase/firestore"; -import {Notification} from "@/hooks/firebase/useGetNotifications"; +import { Notification } from "@/hooks/firebase/useGetNotifications"; export const useDeleteNotification = () => { const queryClient = useQueryClient(); - const {user} = useAuthContext(); + const { user } = useAuthContext(); + const notificationsKey = ["notifications", user?.uid]; return useMutation({ mutationFn: async (id: string) => { @@ -15,23 +16,24 @@ export const useDeleteNotification = () => { .delete(); }, onMutate: async (deletedId) => { - await queryClient.cancelQueries(["notifications", user?.uid]); + await queryClient.cancelQueries({ queryKey: notificationsKey }); - const previousNotifications = queryClient.getQueryData(["notifications", user?.uid]); + const previousNotifications = queryClient.getQueryData(notificationsKey); - queryClient.setQueryData(["notifications", user?.uid], (old) => - old?.filter((notification) => notification?.id! !== deletedId) ?? [] + queryClient.setQueryData( + notificationsKey, + old => old?.filter(notification => notification?.id !== deletedId) ?? [] ); - return {previousNotifications}; + return { previousNotifications }; }, onError: (_err, _deletedId, context) => { if (context?.previousNotifications) { - queryClient.setQueryData(["notifications", user?.uid], context.previousNotifications); + queryClient.setQueryData(notificationsKey, context.previousNotifications); } }, - onSettled: () => { - queryClient.invalidateQueries(["notifications", user?.uid]); - }, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: notificationsKey }); + } }); }; \ No newline at end of file diff --git a/hooks/firebase/useGetEvents.ts b/hooks/firebase/useGetEvents.ts index 51d9324..db4a658 100644 --- a/hooks/firebase/useGetEvents.ts +++ b/hooks/firebase/useGetEvents.ts @@ -40,7 +40,7 @@ export const useGetEvents = () => { const newTimestamp = data.lastSyncTimestamp.seconds; if (newTimestamp > lastSyncTimestamp.current) { lastSyncTimestamp.current = newTimestamp; - queryClient.invalidateQueries(["events", user?.uid, isFamilyView]); + queryClient.invalidateQueries({queryKey: ["events", user?.uid, isFamilyView]}); } } } diff --git a/hooks/firebase/useUpdateEvent.ts b/hooks/firebase/useUpdateEvent.ts index c168f38..5935469 100644 --- a/hooks/firebase/useUpdateEvent.ts +++ b/hooks/firebase/useUpdateEvent.ts @@ -18,7 +18,7 @@ export const useUpdateEvent = () => { } }, onSuccess: () => { - queryClients.invalidateQueries("events") + queryClients.invalidateQueries({queryKey: ["events"]}) } }) } \ No newline at end of file diff --git a/hooks/firebase/useUpdateFeedback.ts b/hooks/firebase/useUpdateFeedback.ts index b89c87b..1607115 100644 --- a/hooks/firebase/useUpdateFeedback.ts +++ b/hooks/firebase/useUpdateFeedback.ts @@ -54,7 +54,7 @@ export const useUpdateFeedback = () => { } }, onSuccess: (updatedFeedback) => { - queryClient.invalidateQueries("feedbacks"); + queryClient.invalidateQueries({queryKey: ["feedbacks"]}) queryClient.setQueryData( ["feedback", updatedFeedback.id], diff --git a/hooks/firebase/useUpdateGrocery.ts b/hooks/firebase/useUpdateGrocery.ts index 0448f8d..1d6c0bb 100644 --- a/hooks/firebase/useUpdateGrocery.ts +++ b/hooks/firebase/useUpdateGrocery.ts @@ -18,7 +18,7 @@ export const useUpdateGrocery = () => { } }, onSuccess: () => { - queryClients.invalidateQueries("groceries") + queryClients.invalidateQueries({queryKey: ["groceries"]}) } }) } \ No newline at end of file diff --git a/hooks/firebase/useUpdateHouseholdName.ts b/hooks/firebase/useUpdateHouseholdName.ts index ed0fa13..a8715e6 100644 --- a/hooks/firebase/useUpdateHouseholdName.ts +++ b/hooks/firebase/useUpdateHouseholdName.ts @@ -44,7 +44,7 @@ export const useUpdateHouseholdName = () => { } }, onSuccess: () => { - queryClient.invalidateQueries("households"); // Invalidate the "households" query to refresh data + queryClient.invalidateQueries({queryKey: ["households"]}); // Invalidate the "households" query to refresh data }, }); }; diff --git a/hooks/firebase/useUpdateNote.ts b/hooks/firebase/useUpdateNote.ts index 823e960..49f3e0b 100644 --- a/hooks/firebase/useUpdateNote.ts +++ b/hooks/firebase/useUpdateNote.ts @@ -54,7 +54,7 @@ export const useUpdateNote = () => { } }, onSuccess: (updatedNote) => { - queryClient.invalidateQueries("braindumps"); + queryClient.invalidateQueries({queryKey: ["braindumps"]}); queryClient.setQueryData( ["feedback", updatedNote.id], diff --git a/hooks/firebase/useUpdateTodo.ts b/hooks/firebase/useUpdateTodo.ts index 34fc97d..f3a775a 100644 --- a/hooks/firebase/useUpdateTodo.ts +++ b/hooks/firebase/useUpdateTodo.ts @@ -165,7 +165,7 @@ export const useUpdateTodo = () => { } }, onSuccess: () => { - queryClients.invalidateQueries("todos") + queryClients.invalidateQueries({queryKey: ["todos"]}) } }) } diff --git a/hooks/firebase/useUpdateUserData.ts b/hooks/firebase/useUpdateUserData.ts index 2948e48..7c841fb 100644 --- a/hooks/firebase/useUpdateUserData.ts +++ b/hooks/firebase/useUpdateUserData.ts @@ -51,7 +51,7 @@ export const useUpdateUserData = () => { } }, onSuccess: () => { - queryClient.invalidateQueries("events"); + queryClient.invalidateQueries({queryKey: ["events"]}) }, }); }; \ No newline at end of file diff --git a/hooks/useCalSync.ts b/hooks/useCalSync.ts index 01f5dc4..2cafce2 100644 --- a/hooks/useCalSync.ts +++ b/hooks/useCalSync.ts @@ -302,7 +302,7 @@ export const useCalSync = () => { useEffect(() => { const handleNotification = async (notification: Notifications.Notification) => { - queryClient.invalidateQueries(["events"]); + queryClient.invalidateQueries({queryKey: ["events"]}); }; const sub = Notifications.addNotificationReceivedListener(handleNotification); diff --git a/hooks/useFetchAndSaveAppleEvents.ts b/hooks/useFetchAndSaveAppleEvents.ts index 53959d6..ffc4a4c 100644 --- a/hooks/useFetchAndSaveAppleEvents.ts +++ b/hooks/useFetchAndSaveAppleEvents.ts @@ -31,7 +31,7 @@ export const useFetchAndSaveAppleEvents = () => { } }, onSuccess: () => { - queryClient.invalidateQueries(["events"]) + queryClient.invalidateQueries({queryKey: ["events"]}) }, }); }; \ No newline at end of file diff --git a/hooks/useFetchAndSaveGoogleEvents.ts b/hooks/useFetchAndSaveGoogleEvents.ts index 339397b..fe3e3b8 100644 --- a/hooks/useFetchAndSaveGoogleEvents.ts +++ b/hooks/useFetchAndSaveGoogleEvents.ts @@ -30,7 +30,7 @@ export const useFetchAndSaveGoogleEvents = () => { } }, onSuccess: (data) => { - queryClient.invalidateQueries(["events"]); + queryClient.invalidateQueries({queryKey: ["events"]}); console.log(`Successfully synced ${data.eventCount} events`); } }); diff --git a/hooks/useFetchAndSaveOutlookEvents.ts b/hooks/useFetchAndSaveOutlookEvents.ts index c28e001..e1fb180 100644 --- a/hooks/useFetchAndSaveOutlookEvents.ts +++ b/hooks/useFetchAndSaveOutlookEvents.ts @@ -130,7 +130,7 @@ export const useFetchAndSaveMicrosoftEvents = () => { } }, onSuccess: (data) => { - queryClient.invalidateQueries(["events"]); + queryClient.invalidateQueries({queryKey: ["events"]}); console.log(`Successfully synced ${data.eventCount} Microsoft events`); }, onError: (error) => {