mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 07:07:16 +00:00
29 lines
880 B
TypeScript
29 lines
880 B
TypeScript
import { useAuthContext } from "@/contexts/AuthContext";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import firestore from "@react-native-firebase/firestore";
|
|
import { IFeedback } from "@/contexts/FeedbackContext";
|
|
|
|
export const useGetFeedbacks = () => {
|
|
const { user: currentUser } = useAuthContext();
|
|
|
|
return useQuery<IFeedback[]>({
|
|
queryKey: ["feedbacks", currentUser?.uid],
|
|
queryFn: async () => {
|
|
try {
|
|
const snapshot = await firestore()
|
|
.collection("Feedbacks")
|
|
.where("creatorId", "==", currentUser?.uid)
|
|
.get();
|
|
|
|
return snapshot.docs.map((doc) => ({
|
|
...doc.data(),
|
|
})) as IFeedback[];
|
|
} catch (error) {
|
|
console.error("Error fetching feedbacks:", error);
|
|
throw error;
|
|
}
|
|
},
|
|
enabled: !!currentUser?.uid, // Only run query if we have a user ID
|
|
});
|
|
};
|