mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 16:34:54 +00:00
Added notifciations
This commit is contained in:
29
hooks/firebase/useGetNotifications.ts
Normal file
29
hooks/firebase/useGetNotifications.ts
Normal 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,
|
||||
};
|
||||
});
|
||||
}
|
||||
})
|
||||
};
|
||||
Reference in New Issue
Block a user