mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 07:07:16 +00:00
Fixes
This commit is contained in:
@ -1,8 +1,10 @@
|
|||||||
module.exports = function (api) {
|
module.exports = function (api) {
|
||||||
|
const env = process.env.NODE_ENV;
|
||||||
api.cache(true);
|
api.cache(true);
|
||||||
let plugins = []
|
|
||||||
|
|
||||||
if (babelEnv !== 'development') {
|
let plugins = [];
|
||||||
|
|
||||||
|
if (env !== 'development') {
|
||||||
plugins.push('transform-remove-console');
|
plugins.push('transform-remove-console');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12,4 +14,4 @@ module.exports = function (api) {
|
|||||||
],
|
],
|
||||||
plugins
|
plugins
|
||||||
};
|
};
|
||||||
};
|
};
|
@ -166,7 +166,7 @@ export const AuthContextProvider: FC<{ children: ReactNode }> = ({children}) =>
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleNotification = async (notification: Notifications.Notification) => {
|
const handleNotification = async (notification: Notifications.Notification) => {
|
||||||
queryClient.invalidateQueries(["notifications"]);
|
queryClient.invalidateQueries({queryKey: ["notifications"]});
|
||||||
};
|
};
|
||||||
|
|
||||||
const sub = Notifications.addNotificationReceivedListener(handleNotification);
|
const sub = Notifications.addNotificationReceivedListener(handleNotification);
|
||||||
|
@ -53,7 +53,7 @@ export const useChangeProfilePicture = (customUserId?: string) => {
|
|||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
// Invalidate queries to refresh profile data
|
// Invalidate queries to refresh profile data
|
||||||
if (!customUserId) {
|
if (!customUserId) {
|
||||||
queryClient.invalidateQueries("Profiles");
|
queryClient.invalidateQueries({queryKey: ["Profiles"]});
|
||||||
refreshProfileData();
|
refreshProfileData();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -83,7 +83,7 @@ export const useCreateEventsFromProvider = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries("events");
|
queryClient.invalidateQueries({queryKey: ["events"]});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
@ -1,47 +1,44 @@
|
|||||||
import {useAuthContext} from "@/contexts/AuthContext";
|
import { useAuthContext } from "@/contexts/AuthContext";
|
||||||
import {useMutation, useQueryClient} from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import firestore from "@react-native-firebase/firestore";
|
import firestore from "@react-native-firebase/firestore";
|
||||||
import { IFeedback } from "@/contexts/FeedbackContext";
|
import { IFeedback } from "@/contexts/FeedbackContext";
|
||||||
|
|
||||||
export const useCreateFeedback = () => {
|
export const useCreateFeedback = () => {
|
||||||
const {user: currentUser, profileData} = useAuthContext()
|
const { user: currentUser } = useAuthContext();
|
||||||
const queryClients = useQueryClient()
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationKey: ["createFeedback"],
|
mutationKey: ["createFeedback"],
|
||||||
mutationFn: async (feedback: Partial<IFeedback>) => {
|
mutationFn: async (feedback: Partial<IFeedback>) => {
|
||||||
try {
|
if (feedback.id) {
|
||||||
if (feedback.id) {
|
const snapshot = await firestore()
|
||||||
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()
|
|
||||||
.collection("Feedbacks")
|
.collection("Feedbacks")
|
||||||
.add({...feedback, id: newDoc.id, creatorId: currentUser?.uid});
|
.where("id", "==", feedback.id)
|
||||||
} catch (e) {
|
.get();
|
||||||
console.error(e);
|
|
||||||
|
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: () => {
|
onSuccess: () => {
|
||||||
queryClients.invalidateQueries("feedbacks")
|
queryClient.invalidateQueries({ queryKey: ["feedbacks"] });
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
export const useCreateFeedbacksFromProvider = () => {
|
export const useCreateFeedbacksFromProvider = () => {
|
||||||
const { user: currentUser } = useAuthContext();
|
const { user: currentUser } = useAuthContext();
|
||||||
@ -50,36 +47,29 @@ export const useCreateFeedbacksFromProvider = () => {
|
|||||||
return useMutation({
|
return useMutation({
|
||||||
mutationKey: ["createFeedbacksFromProvider"],
|
mutationKey: ["createFeedbacksFromProvider"],
|
||||||
mutationFn: async (feedbackDataArray: Partial<IFeedback>[]) => {
|
mutationFn: async (feedbackDataArray: Partial<IFeedback>[]) => {
|
||||||
try {
|
const promises = feedbackDataArray.map(async (feedbackData) => {
|
||||||
const promises = feedbackDataArray.map(async (feedbackData) => {
|
const snapshot = await firestore()
|
||||||
console.log("Processing FeedbackData: ", feedbackData);
|
.collection("Feedbacks")
|
||||||
|
.where("id", "==", feedbackData.id)
|
||||||
|
.get();
|
||||||
|
|
||||||
const snapshot = await firestore()
|
if (snapshot.empty) {
|
||||||
|
return firestore()
|
||||||
.collection("Feedbacks")
|
.collection("Feedbacks")
|
||||||
.where("id", "==", feedbackData.id)
|
.add({ ...feedbackData, creatorId: currentUser?.uid });
|
||||||
.get();
|
}
|
||||||
|
|
||||||
if (snapshot.empty) {
|
const docId = snapshot.docs[0].id;
|
||||||
return firestore()
|
return firestore()
|
||||||
.collection("Feedbacks")
|
.collection("Feedbacks")
|
||||||
.add({ ...feedbackData, creatorId: currentUser?.uid });
|
.doc(docId)
|
||||||
} else {
|
.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);
|
await Promise.all(promises);
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Error creating/updating feedbacks: ", e);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries("feedbacks");
|
queryClient.invalidateQueries({ queryKey: ["feedbacks"] });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
@ -1,26 +1,30 @@
|
|||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import firestore from "@react-native-firebase/firestore";
|
import firestore from "@react-native-firebase/firestore";
|
||||||
import { useAuthContext } from "@/contexts/AuthContext";
|
import { useAuthContext } from "@/contexts/AuthContext";
|
||||||
import {IGrocery} from "@/hooks/firebase/types/groceryData";
|
import { IGrocery } from "@/hooks/firebase/types/groceryData";
|
||||||
|
|
||||||
export const useCreateGrocery = () => {
|
export const useCreateGrocery = () => {
|
||||||
const { user: currentUser, profileData } = useAuthContext();
|
const { user: currentUser, profileData } = useAuthContext();
|
||||||
const queryClients = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
const groceriesKey = ["groceries"];
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationKey: ["createGrocery"],
|
mutationFn: (groceryData: Partial<IGrocery>) => {
|
||||||
mutationFn: async (groceryData: Partial<IGrocery>) => {
|
const newDoc = firestore().collection('Groceries').doc();
|
||||||
try {
|
return firestore()
|
||||||
const newDoc = firestore().collection('Groceries').doc();
|
.collection("Groceries")
|
||||||
await firestore()
|
.add({
|
||||||
.collection("Groceries")
|
...groceryData,
|
||||||
.add({...groceryData, id: newDoc.id, familyId: profileData?.familyId, creatorId: currentUser?.uid})
|
id: newDoc.id,
|
||||||
} catch (e) {
|
familyId: profileData?.familyId,
|
||||||
console.error(e)
|
creatorId: currentUser?.uid
|
||||||
}
|
});
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClients.invalidateQueries("groceries")
|
return queryClient.invalidateQueries({
|
||||||
|
queryKey: groceriesKey,
|
||||||
|
exact: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
};
|
@ -42,7 +42,7 @@ export const useCreateNote = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClients.invalidateQueries("braindumps");
|
queryClients.invalidateQueries({queryKey: ["braindumps"]});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -85,7 +85,7 @@ export const useCreateNotesFromProvider = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries("braindumps");
|
queryClient.invalidateQueries({queryKey: ["braindumps"]});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -140,7 +140,7 @@ export const useCreateTodo = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClients.invalidateQueries("todos")
|
queryClients.invalidateQueries({queryKey: ["todos"]})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ export const useDeleteEvent = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries("events");
|
queryClient.invalidateQueries({queryKey: ["events"]});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
@ -39,7 +39,7 @@ export const useDeleteFeedback = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries("feedbacks");
|
queryClient.invalidateQueries({queryKey: ["feedbacks"]});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,7 @@ export const useDeleteGrocery = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries("groceries");
|
queryClient.invalidateQueries({queryKey: ["groceries"]});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -33,7 +33,7 @@ export const useDeleteNote = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries("braindumps");
|
queryClient.invalidateQueries({queryKey: ["braindumps"]});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import {useMutation, useQueryClient} from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import {useAuthContext} from "@/contexts/AuthContext";
|
import { useAuthContext } from "@/contexts/AuthContext";
|
||||||
import firestore from "@react-native-firebase/firestore";
|
import firestore from "@react-native-firebase/firestore";
|
||||||
import {Notification} from "@/hooks/firebase/useGetNotifications";
|
import { Notification } from "@/hooks/firebase/useGetNotifications";
|
||||||
|
|
||||||
export const useDeleteNotification = () => {
|
export const useDeleteNotification = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const {user} = useAuthContext();
|
const { user } = useAuthContext();
|
||||||
|
const notificationsKey = ["notifications", user?.uid];
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async (id: string) => {
|
mutationFn: async (id: string) => {
|
||||||
@ -15,23 +16,24 @@ export const useDeleteNotification = () => {
|
|||||||
.delete();
|
.delete();
|
||||||
},
|
},
|
||||||
onMutate: async (deletedId) => {
|
onMutate: async (deletedId) => {
|
||||||
await queryClient.cancelQueries(["notifications", user?.uid]);
|
await queryClient.cancelQueries({ queryKey: notificationsKey });
|
||||||
|
|
||||||
const previousNotifications = queryClient.getQueryData<Notification[]>(["notifications", user?.uid]);
|
const previousNotifications = queryClient.getQueryData<Notification[]>(notificationsKey);
|
||||||
|
|
||||||
queryClient.setQueryData<Notification[]>(["notifications", user?.uid], (old) =>
|
queryClient.setQueryData<Notification[]>(
|
||||||
old?.filter((notification) => notification?.id! !== deletedId) ?? []
|
notificationsKey,
|
||||||
|
old => old?.filter(notification => notification?.id !== deletedId) ?? []
|
||||||
);
|
);
|
||||||
|
|
||||||
return {previousNotifications};
|
return { previousNotifications };
|
||||||
},
|
},
|
||||||
onError: (_err, _deletedId, context) => {
|
onError: (_err, _deletedId, context) => {
|
||||||
if (context?.previousNotifications) {
|
if (context?.previousNotifications) {
|
||||||
queryClient.setQueryData(["notifications", user?.uid], context.previousNotifications);
|
queryClient.setQueryData(notificationsKey, context.previousNotifications);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSettled: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries(["notifications", user?.uid]);
|
queryClient.invalidateQueries({ queryKey: notificationsKey });
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
@ -40,7 +40,7 @@ export const useGetEvents = () => {
|
|||||||
const newTimestamp = data.lastSyncTimestamp.seconds;
|
const newTimestamp = data.lastSyncTimestamp.seconds;
|
||||||
if (newTimestamp > lastSyncTimestamp.current) {
|
if (newTimestamp > lastSyncTimestamp.current) {
|
||||||
lastSyncTimestamp.current = newTimestamp;
|
lastSyncTimestamp.current = newTimestamp;
|
||||||
queryClient.invalidateQueries(["events", user?.uid, isFamilyView]);
|
queryClient.invalidateQueries({queryKey: ["events", user?.uid, isFamilyView]});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ export const useUpdateEvent = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClients.invalidateQueries("events")
|
queryClients.invalidateQueries({queryKey: ["events"]})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
@ -54,7 +54,7 @@ export const useUpdateFeedback = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: (updatedFeedback) => {
|
onSuccess: (updatedFeedback) => {
|
||||||
queryClient.invalidateQueries("feedbacks");
|
queryClient.invalidateQueries({queryKey: ["feedbacks"]})
|
||||||
|
|
||||||
queryClient.setQueryData(
|
queryClient.setQueryData(
|
||||||
["feedback", updatedFeedback.id],
|
["feedback", updatedFeedback.id],
|
||||||
|
@ -18,7 +18,7 @@ export const useUpdateGrocery = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClients.invalidateQueries("groceries")
|
queryClients.invalidateQueries({queryKey: ["groceries"]})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
@ -44,7 +44,7 @@ export const useUpdateHouseholdName = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries("households"); // Invalidate the "households" query to refresh data
|
queryClient.invalidateQueries({queryKey: ["households"]}); // Invalidate the "households" query to refresh data
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -54,7 +54,7 @@ export const useUpdateNote = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: (updatedNote) => {
|
onSuccess: (updatedNote) => {
|
||||||
queryClient.invalidateQueries("braindumps");
|
queryClient.invalidateQueries({queryKey: ["braindumps"]});
|
||||||
|
|
||||||
queryClient.setQueryData(
|
queryClient.setQueryData(
|
||||||
["feedback", updatedNote.id],
|
["feedback", updatedNote.id],
|
||||||
|
@ -165,7 +165,7 @@ export const useUpdateTodo = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClients.invalidateQueries("todos")
|
queryClients.invalidateQueries({queryKey: ["todos"]})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ export const useUpdateUserData = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries("events");
|
queryClient.invalidateQueries({queryKey: ["events"]})
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
@ -302,7 +302,7 @@ export const useCalSync = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleNotification = async (notification: Notifications.Notification) => {
|
const handleNotification = async (notification: Notifications.Notification) => {
|
||||||
queryClient.invalidateQueries(["events"]);
|
queryClient.invalidateQueries({queryKey: ["events"]});
|
||||||
};
|
};
|
||||||
|
|
||||||
const sub = Notifications.addNotificationReceivedListener(handleNotification);
|
const sub = Notifications.addNotificationReceivedListener(handleNotification);
|
||||||
|
@ -31,7 +31,7 @@ export const useFetchAndSaveAppleEvents = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries(["events"])
|
queryClient.invalidateQueries({queryKey: ["events"]})
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
@ -30,7 +30,7 @@ export const useFetchAndSaveGoogleEvents = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
queryClient.invalidateQueries(["events"]);
|
queryClient.invalidateQueries({queryKey: ["events"]});
|
||||||
console.log(`Successfully synced ${data.eventCount} events`);
|
console.log(`Successfully synced ${data.eventCount} events`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -130,7 +130,7 @@ export const useFetchAndSaveMicrosoftEvents = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
queryClient.invalidateQueries(["events"]);
|
queryClient.invalidateQueries({queryKey: ["events"]});
|
||||||
console.log(`Successfully synced ${data.eventCount} Microsoft events`);
|
console.log(`Successfully synced ${data.eventCount} Microsoft events`);
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
|
Reference in New Issue
Block a user