Colors, fix family view, updated version

This commit is contained in:
Milan Paunovic
2024-10-10 02:00:14 +02:00
parent 2c099740a2
commit ca0b55c494
12 changed files with 545 additions and 659 deletions
+1
View File
@@ -19,6 +19,7 @@ export interface UserProfile {
uid?: string;
googleToken?: string;
microsoftToken?: string;
eventColor?: string
}
export interface ParentProfile extends UserProfile {
+27 -15
View File
@@ -1,31 +1,43 @@
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";
import {colorMap} from "@/contexts/SettingsContext";
export const useGetEvents = () => {
const {user} = useAuthContext()
export const useGetEvents = (isFamilyView: boolean) => {
const { user, profileData } = useAuthContext();
return useQuery({
queryKey: ["events", user?.uid],
queryKey: ["events", user?.uid, isFamilyView],
queryFn: async () => {
const snapshot = await firestore()
const eventsQuery = firestore()
.collection("Events")
.where("creatorId", "==", user?.uid)
.get();
.where("creatorId", "==", user?.uid);
const events: ICalendarEventBase[] = snapshot.docs.map((doc) => {
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 {
title: data.title,
start: new Date(data.startDate.seconds * 1000),
end: new Date(data.endDate.seconds * 1000),
hideHours: data.allDay,
eventColor: eventColor,
};
});
return events;
}
})
}
}));
},
});
};
+1 -1
View File
@@ -5,7 +5,7 @@ import {UserProfile} from "@/hooks/firebase/types/profileTypes";
import {FirebaseAuthTypes} from "@react-native-firebase/auth";
export const useUpdateUserData = () => {
const {user: currentUser, setProfileData, refreshProfileData} = useAuthContext();
const {user: currentUser, refreshProfileData} = useAuthContext();
return useMutation({
mutationKey: ["updateUserData"],