mirror of
https://github.com/urosran/cally.git
synced 2025-07-15 01:35:22 +00:00
Notification changes
This commit is contained in:
@ -1,11 +1,34 @@
|
||||
import {useQuery} from "react-query";
|
||||
import { useQuery } from "react-query";
|
||||
import firestore from "@react-native-firebase/firestore";
|
||||
import {useAuthContext} from "@/contexts/AuthContext";
|
||||
import { useAuthContext } from "@/contexts/AuthContext";
|
||||
|
||||
interface FirestoreTimestamp {
|
||||
seconds: number;
|
||||
nanoseconds: number;
|
||||
}
|
||||
|
||||
interface NotificationFirestore {
|
||||
creatorId: string;
|
||||
familyId: string;
|
||||
content: string;
|
||||
eventId: string;
|
||||
timestamp: FirestoreTimestamp;
|
||||
date?: FirestoreTimestamp;
|
||||
}
|
||||
|
||||
export interface Notification {
|
||||
creatorId: string;
|
||||
familyId: string;
|
||||
content: string;
|
||||
eventId: string;
|
||||
timestamp: Date;
|
||||
date?: Date;
|
||||
}
|
||||
|
||||
export const useGetNotifications = () => {
|
||||
const { user, profileData } = useAuthContext();
|
||||
|
||||
return useQuery({
|
||||
return useQuery<Notification[], Error>({
|
||||
queryKey: ["notifications", user?.uid],
|
||||
queryFn: async () => {
|
||||
const snapshot = await firestore()
|
||||
@ -14,16 +37,14 @@ export const useGetNotifications = () => {
|
||||
.get();
|
||||
|
||||
return snapshot.docs.map((doc) => {
|
||||
const data = doc.data();
|
||||
const data = doc.data() as NotificationFirestore;
|
||||
|
||||
return {...data, timestamp: new Date(data.timestamp.seconds * 1000 + data.timestamp.nanoseconds / 1e6)} as {
|
||||
creatorId: string,
|
||||
familyId: string,
|
||||
content: string,
|
||||
eventId: string,
|
||||
timestamp: Date,
|
||||
return {
|
||||
...data,
|
||||
timestamp: new Date(data.timestamp.seconds * 1000 + data.timestamp.nanoseconds / 1e6),
|
||||
date: data.date ? new Date(data.date.seconds * 1000 + data.date.nanoseconds / 1e6) : undefined
|
||||
};
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user