mirror of
https://github.com/urosran/cally.git
synced 2025-07-15 09:45:20 +00:00
29 lines
987 B
TypeScript
29 lines
987 B
TypeScript
import {useQuery} from "react-query";
|
|
import firestore from "@react-native-firebase/firestore";
|
|
import {useAuthContext} from "@/contexts/AuthContext";
|
|
|
|
export const useGetNotifications = () => {
|
|
const { user, profileData } = useAuthContext();
|
|
|
|
return useQuery({
|
|
queryKey: ["notifications", user?.uid],
|
|
queryFn: async () => {
|
|
const snapshot = await firestore()
|
|
.collection("Notifications")
|
|
.where("familyId", "==", profileData?.familyId)
|
|
.get();
|
|
|
|
return snapshot.docs.map((doc) => {
|
|
const data = doc.data();
|
|
|
|
return {...data, timestamp: new Date(data.timestamp.seconds * 1000 + data.timestamp.nanoseconds / 1e6)} as {
|
|
creatorId: string,
|
|
familyId: string,
|
|
content: string,
|
|
eventId: string,
|
|
timestamp: Date,
|
|
};
|
|
});
|
|
}
|
|
})
|
|
}; |