Added notifciations

This commit is contained in:
Milan Paunovic
2024-11-04 01:01:59 +01:00
parent 848211c3c8
commit 84a974f3f7
8 changed files with 153 additions and 16 deletions

View File

@ -0,0 +1,29 @@
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,
};
});
}
})
};