mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 15:17:17 +00:00
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import {useQuery} from "@tanstack/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) => {
|
|
let documentData = doc.data();
|
|
|
|
return {
|
|
...documentData,
|
|
uid: doc.id
|
|
}
|
|
}).filter((doc) => doc.id !== user?.uid) as UserProfile[];
|
|
}
|
|
|
|
return snapshot.docs.map((doc) => {
|
|
let documentData = doc.data();
|
|
|
|
return {
|
|
...documentData,
|
|
uid: doc.id
|
|
}
|
|
}) as UserProfile[];
|
|
}
|
|
})
|
|
} |