mirror of
https://github.com/urosran/cally.git
synced 2026-10-23 07:17:54 +00:00
Faimly
This commit is contained in:
@@ -4,6 +4,7 @@ import { useAuthContext } from "@/contexts/AuthContext";
|
||||
import { useAtomValue } from "jotai";
|
||||
import { isFamilyViewAtom } from "@/components/pages/calendar/atoms";
|
||||
import { colorMap } from "@/constants/colorMap";
|
||||
import {uuidv4} from "@firebase/util";
|
||||
|
||||
export const useGetEvents = () => {
|
||||
const { user, profileData } = useAuthContext();
|
||||
@@ -20,23 +21,22 @@ export const useGetEvents = () => {
|
||||
|
||||
// If family view is active, include family, creator, and attendee events
|
||||
if (isFamilyView) {
|
||||
|
||||
const familyQuery = db.collection("Events").where("familyID", "==", familyId);
|
||||
const creatorQuery = db.collection("Events").where("creatorId", "==", userId);
|
||||
const familyQuery = db.collection("Events").where("familyId", "==", familyId);
|
||||
const attendeeQuery = db.collection("Events").where("attendees", "array-contains", userId);
|
||||
|
||||
const [familySnapshot, creatorSnapshot, attendeeSnapshot] = await Promise.all([
|
||||
const [familySnapshot, attendeeSnapshot] = await Promise.all([
|
||||
familyQuery.get(),
|
||||
creatorQuery.get(),
|
||||
attendeeQuery.get(),
|
||||
]);
|
||||
|
||||
// Collect all events
|
||||
const familyEvents = familySnapshot.docs.map(doc => doc.data());
|
||||
const creatorEvents = creatorSnapshot.docs.map(doc => doc.data());
|
||||
const attendeeEvents = attendeeSnapshot.docs.map(doc => doc.data());
|
||||
|
||||
allEvents = [...familyEvents, ...creatorEvents, ...attendeeEvents];
|
||||
// console.log("Family events not in creator query: ", familyEvents.filter(event => !creatorEvents.some(creatorEvent => creatorEvent.id === event.id)));
|
||||
|
||||
|
||||
allEvents = [...familyEvents, ...attendeeEvents];
|
||||
} else {
|
||||
// Only include creator and attendee events when family view is off
|
||||
const creatorQuery = db.collection("Events").where("creatorId", "==", userId);
|
||||
@@ -59,7 +59,7 @@ export const useGetEvents = () => {
|
||||
if (event.id) {
|
||||
uniqueEventsMap.set(event.id, event); // Ensure uniqueness for events with IDs
|
||||
} else {
|
||||
uniqueEventsMap.set(Math.random().toString(36), event); // Generate a temp key for events without ID
|
||||
uniqueEventsMap.set(uuidv4(), event); // Generate a temp key for events without ID
|
||||
}
|
||||
});
|
||||
const uniqueEvents = Array.from(uniqueEventsMap.values());
|
||||
|
||||
Reference in New Issue
Block a user