This commit is contained in:
Milan Paunovic
2024-11-01 23:45:05 +01:00
parent 18223c5f92
commit c4e4a4a798
2 changed files with 11 additions and 11 deletions

View File

@ -49,7 +49,7 @@ export const EventCalendar: React.FC<EventCalendarProps> = React.memo(
(event: CalendarEvent) => { (event: CalendarEvent) => {
if (mode === "day" || mode === "week") { if (mode === "day" || mode === "week") {
setEditVisible(true); setEditVisible(true);
console.log({event}); // console.log({event});
setEventForEdit(event); setEventForEdit(event);
} else { } else {
setMode("day"); setMode("day");
@ -88,7 +88,7 @@ export const EventCalendar: React.FC<EventCalendarProps> = React.memo(
[profileData] [profileData]
); );
console.log({memoizedWeekStartsOn, profileData: profileData?.firstDayOfWeek}) // console.log({memoizedWeekStartsOn, profileData: profileData?.firstDayOfWeek})
const isSameDate = useCallback((date1: Date, date2: Date) => { const isSameDate = useCallback((date1: Date, date2: Date) => {
return ( return (
@ -155,7 +155,7 @@ export const EventCalendar: React.FC<EventCalendarProps> = React.memo(
}, {} as Record<string, CalendarEvent[]>); }, {} as Record<string, CalendarEvent[]>);
const endTime = Date.now(); const endTime = Date.now();
console.log("memoizedEvents computation time:", endTime - startTime, "ms"); // console.log("memoizedEvents computation time:", endTime - startTime, "ms");
return {enrichedEvents, filteredEvents}; return {enrichedEvents, filteredEvents};
}, [events, selectedDate, mode]); }, [events, selectedDate, mode]);

View File

@ -4,6 +4,7 @@ import { useAuthContext } from "@/contexts/AuthContext";
import { useAtomValue } from "jotai"; import { useAtomValue } from "jotai";
import { isFamilyViewAtom } from "@/components/pages/calendar/atoms"; import { isFamilyViewAtom } from "@/components/pages/calendar/atoms";
import { colorMap } from "@/constants/colorMap"; import { colorMap } from "@/constants/colorMap";
import {uuidv4} from "@firebase/util";
export const useGetEvents = () => { export const useGetEvents = () => {
const { user, profileData } = useAuthContext(); const { user, profileData } = useAuthContext();
@ -20,23 +21,22 @@ export const useGetEvents = () => {
// If family view is active, include family, creator, and attendee events // If family view is active, include family, creator, and attendee events
if (isFamilyView) { if (isFamilyView) {
const familyQuery = db.collection("Events").where("familyId", "==", familyId);
const familyQuery = db.collection("Events").where("familyID", "==", familyId);
const creatorQuery = db.collection("Events").where("creatorId", "==", userId);
const attendeeQuery = db.collection("Events").where("attendees", "array-contains", userId); 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(), familyQuery.get(),
creatorQuery.get(),
attendeeQuery.get(), attendeeQuery.get(),
]); ]);
// Collect all events // Collect all events
const familyEvents = familySnapshot.docs.map(doc => doc.data()); const familyEvents = familySnapshot.docs.map(doc => doc.data());
const creatorEvents = creatorSnapshot.docs.map(doc => doc.data());
const attendeeEvents = attendeeSnapshot.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 { } else {
// Only include creator and attendee events when family view is off // Only include creator and attendee events when family view is off
const creatorQuery = db.collection("Events").where("creatorId", "==", userId); const creatorQuery = db.collection("Events").where("creatorId", "==", userId);
@ -59,7 +59,7 @@ export const useGetEvents = () => {
if (event.id) { if (event.id) {
uniqueEventsMap.set(event.id, event); // Ensure uniqueness for events with IDs uniqueEventsMap.set(event.id, event); // Ensure uniqueness for events with IDs
} else { } 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()); const uniqueEvents = Array.from(uniqueEventsMap.values());