mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 15:17:17 +00:00

- Added creatorId to the grocery item in db and showed the name of the user that requested to add the new grocery
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import {useQuery} from "react-query";
|
|
import firestore from "@react-native-firebase/firestore";
|
|
import {useAuthContext} from "@/contexts/AuthContext";
|
|
|
|
export const useGetGroceries = () => {
|
|
const { user, profileData } = useAuthContext();
|
|
|
|
return useQuery({
|
|
queryKey: ["groceries", user?.uid],
|
|
queryFn: async () => {
|
|
const snapshot = await firestore()
|
|
.collection("Groceries")
|
|
.where("familyId", "==", profileData?.familyId)
|
|
.get();
|
|
|
|
return snapshot.docs.map((doc) => {
|
|
const data = doc.data();
|
|
|
|
return {
|
|
id: doc.id,
|
|
title: data.title,
|
|
category: data.category,
|
|
approved: data.approved,
|
|
bought: data.bought,
|
|
recurring: data.recurring,
|
|
frequency: data.frequency,
|
|
creatorId: data.creatorId
|
|
};
|
|
});
|
|
}
|
|
})
|
|
}; |