mirror of
https://github.com/urosran/cally.git
synced 2025-07-15 09:45:20 +00:00
tablet view fixes, grocery item fix
This commit is contained in:
31
hooks/firebase/useGetUserById.ts
Normal file
31
hooks/firebase/useGetUserById.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { useQuery } from "react-query";
|
||||
import { UserProfile } from "@/hooks/firebase/types/profileTypes";
|
||||
import firestore from "@react-native-firebase/firestore";
|
||||
|
||||
export const useGetUserById = (uid: string | undefined) => {
|
||||
return useQuery({
|
||||
queryKey: ["getUserById", uid],
|
||||
queryFn: async (): Promise<UserProfile | null> => {
|
||||
if (!uid) return null;
|
||||
|
||||
try {
|
||||
const doc = await firestore()
|
||||
.collection("Profiles")
|
||||
.doc(uid)
|
||||
.get();
|
||||
|
||||
if (!doc.exists) return null;
|
||||
|
||||
const data = doc.data();
|
||||
return {
|
||||
...data,
|
||||
uid: doc.id,
|
||||
} as UserProfile;
|
||||
} catch (error) {
|
||||
console.error("Error retrieving user:", error);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
enabled: !!uid
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user