mirror of
https://github.com/urosran/cally.git
synced 2025-07-15 01:35:22 +00:00
24 lines
902 B
TypeScript
24 lines
902 B
TypeScript
import {useQuery} from "react-query";
|
|
import firestore from "@react-native-firebase/firestore";
|
|
import {useAuthContext} from "@/contexts/AuthContext";
|
|
import {UserProfile} from "@/hooks/firebase/types/profileTypes";
|
|
|
|
export const useGetFamilyMembers = (excludeSelf?: boolean) => {
|
|
const {profileData, user} = useAuthContext()
|
|
|
|
return useQuery({
|
|
queryKey: ["familyMembers", user?.uid],
|
|
queryFn: async (): Promise<undefined | UserProfile[]> => {
|
|
const snapshot = await firestore()
|
|
.collection("Profiles")
|
|
.where("familyId", "==", profileData?.familyId)
|
|
.get();
|
|
|
|
if (excludeSelf) {
|
|
return snapshot.docs.map((doc) => doc.data()).filter((doc) => doc.id !== user?.uid) as UserProfile[];
|
|
}
|
|
|
|
return snapshot.docs.map((doc) => doc.data()) as UserProfile[];
|
|
}
|
|
})
|
|
} |