mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 07:07:16 +00:00

- Added new hook for updating events - Updated the selected event in db - Added document id as id to the event object when fetching events - Removed unused react-native-google sign-in library
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import {useQuery} from "react-query";
|
|
import firestore from "@react-native-firebase/firestore";
|
|
import {useAuthContext} from "@/contexts/AuthContext";
|
|
import {colorMap} from "@/contexts/SettingsContext";
|
|
|
|
export const useGetEvents = (isFamilyView: boolean) => {
|
|
const { user, profileData } = useAuthContext();
|
|
|
|
return useQuery({
|
|
queryKey: ["events", user?.uid, isFamilyView],
|
|
queryFn: async () => {
|
|
const eventsQuery = firestore()
|
|
.collection("Events")
|
|
.where("creatorId", "==", user?.uid);
|
|
|
|
if (isFamilyView) {
|
|
eventsQuery.where("familyID", "==", profileData?.familyId);
|
|
}
|
|
|
|
const snapshot = await eventsQuery.get();
|
|
|
|
return await Promise.all(snapshot.docs.map(async (doc) => {
|
|
const data = doc.data();
|
|
|
|
const profileSnapshot = await firestore()
|
|
.collection("Profiles")
|
|
.doc(data.creatorId)
|
|
.get();
|
|
|
|
const profileData = profileSnapshot.data();
|
|
const eventColor: string = profileData?.eventColor || colorMap.pink // Default color if not found
|
|
|
|
return {
|
|
id: doc.id,
|
|
title: data.title,
|
|
start: new Date(data.startDate.seconds * 1000),
|
|
end: new Date(data.endDate.seconds * 1000),
|
|
hideHours: data.allDay,
|
|
eventColor: eventColor,
|
|
};
|
|
}));
|
|
},
|
|
});
|
|
};
|