mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 07:07:16 +00:00
31 lines
1020 B
TypeScript
31 lines
1020 B
TypeScript
import {useQuery} from "react-query";
|
|
import firestore from "@react-native-firebase/firestore";
|
|
import {ReactElement} from "react";
|
|
import {useAuthContext} from "@/contexts/AuthContext";
|
|
import {ICalendarEventBase} from "react-native-big-calendar";
|
|
|
|
export const useGetEvents = () => {
|
|
const {user} = useAuthContext()
|
|
|
|
return useQuery({
|
|
queryKey: ["events", user?.uid],
|
|
queryFn: async () => {
|
|
const snapshot = await firestore()
|
|
.collection("Events")
|
|
.where("creatorId", "==", user?.uid)
|
|
.get();
|
|
|
|
const events: ICalendarEventBase[] = snapshot.docs.map((doc) => {
|
|
const data = doc.data();
|
|
return {
|
|
title: data.title,
|
|
start: new Date(data.startDate.seconds * 1000),
|
|
end: new Date(data.endDate.seconds * 1000),
|
|
hideHours: data.allDay,
|
|
};
|
|
});
|
|
|
|
return events;
|
|
}
|
|
})
|
|
} |