mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 00:24:53 +00:00
Merge branch 'main' into dev
# Conflicts: # components/pages/calendar/DetailedCalendar.tsx
This commit is contained in:
@ -8,7 +8,6 @@ import {modeAtom, selectedDateAtom} from "@/components/pages/calendar/atoms";
|
||||
import {format, isSameDay} from "date-fns";
|
||||
import * as Device from "expo-device";
|
||||
import {Mode} from "react-native-big-calendar";
|
||||
import { FontAwesome5 } from '@expo/vector-icons';
|
||||
|
||||
export const CalendarHeader = memo(() => {
|
||||
const [selectedDate, setSelectedDate] = useAtom(selectedDateAtom);
|
||||
@ -48,17 +47,25 @@ export const CalendarHeader = memo(() => {
|
||||
const getInitialIndex = () => {
|
||||
if (isTablet) {
|
||||
switch (mode) {
|
||||
case "day": return 0;
|
||||
case "week": return 1;
|
||||
case "month": return 2;
|
||||
default: return 1;
|
||||
case "day":
|
||||
return 0;
|
||||
case "week":
|
||||
return 1;
|
||||
case "month":
|
||||
return 2;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
switch (mode) {
|
||||
case "day": return 0;
|
||||
case "3days": return 1;
|
||||
case "month": return 2;
|
||||
default: return 1;
|
||||
case "day":
|
||||
return 0;
|
||||
case "3days":
|
||||
return 1;
|
||||
case "month":
|
||||
return 2;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -70,7 +77,7 @@ export const CalendarHeader = memo(() => {
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
paddingHorizontal: 10,
|
||||
paddingVertical: 8,
|
||||
paddingVertical: isTablet ? 8 : 0,
|
||||
borderRadius: 20,
|
||||
borderBottomLeftRadius: 0,
|
||||
borderBottomRightRadius: 0,
|
||||
@ -79,9 +86,11 @@ export const CalendarHeader = memo(() => {
|
||||
centerV
|
||||
>
|
||||
<View row centerV gap-3>
|
||||
<Text style={{fontFamily: "Manrope_500Medium", fontSize: 17}}>
|
||||
{selectedDate.getFullYear()}
|
||||
</Text>
|
||||
{isTablet && (
|
||||
<Text style={{fontFamily: "Manrope_500Medium", fontSize: 17}}>
|
||||
{selectedDate.getFullYear()}
|
||||
</Text>
|
||||
)}
|
||||
<Picker
|
||||
value={months[selectedDate.getMonth()]}
|
||||
placeholder={"Select Month"}
|
||||
@ -108,7 +117,7 @@ export const CalendarHeader = memo(() => {
|
||||
style={styles.todayButton}
|
||||
onPress={() => setSelectedDate(new Date())}
|
||||
>
|
||||
<MaterialIcons name="calendar-today" size={30} color="#5f6368" />
|
||||
<MaterialIcons name="calendar-today" size={30} color="#5f6368"/>
|
||||
<Text style={styles.todayDate}>{format(new Date(), "d")}</Text>
|
||||
</Button>
|
||||
<View>
|
||||
|
||||
@ -12,21 +12,43 @@ import {isToday} from "date-fns";
|
||||
import { View } from "react-native-ui-lib";
|
||||
import { DeviceType } from "expo-device";
|
||||
import * as Device from "expo-device"
|
||||
import {View} from "react-native-ui-lib";
|
||||
import {useAtomCallback} from 'jotai/utils'
|
||||
|
||||
interface EventCalendarProps {
|
||||
calendarHeight: number;
|
||||
calendarWidth: number;
|
||||
mode: "week" | "month" | "day" | "3days";
|
||||
onLoad?: () => void;
|
||||
}
|
||||
|
||||
export const DetailedCalendar: React.FC<EventCalendarProps> = ({calendarHeight, calendarWidth}) => {
|
||||
const MemoizedEventCell = React.memo(EventCell);
|
||||
|
||||
export const DetailedCalendar: React.FC<EventCalendarProps> = React.memo((
|
||||
{
|
||||
calendarHeight,
|
||||
calendarWidth,
|
||||
mode,
|
||||
onLoad
|
||||
}) => {
|
||||
const {profileData} = useAuthContext();
|
||||
const selectedDate = useAtomValue(selectedDateAtom);
|
||||
const mode = useAtomValue(modeAtom);
|
||||
const {data: familyMembers} = useGetFamilyMembers();
|
||||
const calendarRef = useRef<CalendarKitHandle>(null);
|
||||
const {data: events} = useGetEvents();
|
||||
const selectedUser = useAtomValue(selectedUserAtom);
|
||||
|
||||
const checkModeAndGoToDate = useAtomCallback(useCallback((get) => {
|
||||
const currentMode = get(modeAtom);
|
||||
if ((selectedDate && isToday(selectedDate)) || currentMode === "month") {
|
||||
calendarRef?.current?.goToDate({date: selectedDate});
|
||||
}
|
||||
}, [selectedDate]));
|
||||
|
||||
useEffect(() => {
|
||||
checkModeAndGoToDate();
|
||||
}, [selectedDate, checkModeAndGoToDate]);
|
||||
|
||||
const {data: formattedEvents} = useFormattedEvents(events ?? [], selectedDate, selectedUser);
|
||||
const {
|
||||
handlePressEvent,
|
||||
@ -44,7 +66,7 @@ export const DetailedCalendar: React.FC<EventCalendarProps> = ({calendarHeight,
|
||||
|
||||
const headerProps = useMemo(() => ({
|
||||
dayBarHeight: 60,
|
||||
headerBottomHeight: 20
|
||||
headerBottomHeight: 20,
|
||||
}), []);
|
||||
|
||||
const bodyProps = useMemo(() => ({
|
||||
@ -60,26 +82,20 @@ export const DetailedCalendar: React.FC<EventCalendarProps> = ({calendarHeight,
|
||||
initialDate: selectedDate.toISOString(),
|
||||
}), [selectedDate]);
|
||||
|
||||
const renderEvent = useCallback((event: any) => {
|
||||
const attendees = useMemo(() =>
|
||||
familyMembers?.filter(member => event?.attendees?.includes(member?.uid!)) || [],
|
||||
[familyMembers, event.attendees]
|
||||
);
|
||||
const getAttendees = useCallback((event: any) => {
|
||||
return familyMembers?.filter(member => event?.attendees?.includes(member?.uid!)) || [];
|
||||
}, [familyMembers]);
|
||||
|
||||
const renderEvent = useCallback((event: any) => {
|
||||
const attendees = getAttendees(event);
|
||||
return (
|
||||
<EventCell
|
||||
<MemoizedEventCell
|
||||
event={event}
|
||||
onPress={handlePressEvent}
|
||||
attendees={attendees}
|
||||
/>
|
||||
);
|
||||
}, [familyMembers, handlePressEvent]);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedDate && isToday(selectedDate)) {
|
||||
calendarRef?.current?.goToDate({date: selectedDate});
|
||||
}
|
||||
}, [selectedDate]);
|
||||
}, [familyMembers, handlePressEvent, getAttendees]);
|
||||
|
||||
return (
|
||||
<CalendarContainer
|
||||
@ -87,12 +103,12 @@ export const DetailedCalendar: React.FC<EventCalendarProps> = ({calendarHeight,
|
||||
{...containerProps}
|
||||
numberOfDays={numberOfDays}
|
||||
calendarWidth={calendarWidth}
|
||||
|
||||
onDateChanged={debouncedOnDateChanged}
|
||||
firstDay={firstDay}
|
||||
events={formattedEvents ?? []}
|
||||
onPressEvent={handlePressEvent}
|
||||
onPressBackground={handlePressCell}
|
||||
onLoad={onLoad}
|
||||
>
|
||||
<CalendarHeader {...headerProps} />
|
||||
<CalendarBody
|
||||
@ -102,6 +118,8 @@ export const DetailedCalendar: React.FC<EventCalendarProps> = ({calendarHeight,
|
||||
{Device.deviceType === DeviceType.TABLET && <View style={{backgroundColor: 'white', height: '9%', width: '100%'}}/>}
|
||||
</CalendarContainer>
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
DetailedCalendar.displayName = 'DetailedCalendar';
|
||||
|
||||
export default DetailedCalendar;
|
||||
@ -1,15 +1,23 @@
|
||||
import React from 'react';
|
||||
import {StyleSheet, View, ActivityIndicator} from 'react-native';
|
||||
import {Text} from 'react-native-ui-lib';
|
||||
import {useGetEvents} from '@/hooks/firebase/useGetEvents';
|
||||
import {useCalSync} from '@/hooks/useCalSync';
|
||||
import {useSyncEvents} from '@/hooks/useSyncOnScroll';
|
||||
import {useAtom} from 'jotai';
|
||||
import {
|
||||
modeAtom,
|
||||
} from './atoms';
|
||||
import {MonthCalendar} from "@/components/pages/calendar/MonthCalendar";
|
||||
import {DetailedCalendar} from "@/components/pages/calendar/DetailedCalendar";
|
||||
import { StyleSheet, View, ActivityIndicator } from 'react-native';
|
||||
import { Text } from 'react-native-ui-lib';
|
||||
import Animated, {
|
||||
withTiming,
|
||||
useAnimatedStyle,
|
||||
FadeOut,
|
||||
useSharedValue,
|
||||
runOnJS
|
||||
} from 'react-native-reanimated';
|
||||
import { useGetEvents } from '@/hooks/firebase/useGetEvents';
|
||||
import { useCalSync } from '@/hooks/useCalSync';
|
||||
import { useSyncEvents } from '@/hooks/useSyncOnScroll';
|
||||
import { useAtom } from 'jotai';
|
||||
import { modeAtom } from './atoms';
|
||||
import { MonthCalendar } from "@/components/pages/calendar/MonthCalendar";
|
||||
import DetailedCalendar from "@/components/pages/calendar/DetailedCalendar";
|
||||
import * as Device from "expo-device";
|
||||
|
||||
export type CalendarMode = 'month' | 'day' | '3days' | 'week';
|
||||
|
||||
interface EventCalendarProps {
|
||||
calendarHeight: number;
|
||||
@ -17,33 +25,81 @@ interface EventCalendarProps {
|
||||
}
|
||||
|
||||
export const EventCalendar: React.FC<EventCalendarProps> = React.memo((props) => {
|
||||
const {data: events, isLoading} = useGetEvents();
|
||||
const [mode] = useAtom(modeAtom);
|
||||
const {isSyncing} = useSyncEvents();
|
||||
const { isLoading } = useGetEvents();
|
||||
const [mode] = useAtom<CalendarMode>(modeAtom);
|
||||
const { isSyncing } = useSyncEvents();
|
||||
const isTablet = Device.deviceType === Device.DeviceType.TABLET;
|
||||
const isCalendarReady = useSharedValue(false);
|
||||
useCalSync();
|
||||
|
||||
if (isLoading || isSyncing) {
|
||||
return (
|
||||
<View style={styles.loadingContainer}>
|
||||
{isSyncing && <Text>Syncing...</Text>}
|
||||
<ActivityIndicator size="large" color="#0000ff"/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
const handleRenderComplete = React.useCallback(() => {
|
||||
isCalendarReady.value = true;
|
||||
}, []);
|
||||
|
||||
return mode === "month"
|
||||
? <MonthCalendar {...props} />
|
||||
: <DetailedCalendar {...props} />;
|
||||
});
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
loadingContainer: {
|
||||
const containerStyle = useAnimatedStyle(() => ({
|
||||
opacity: withTiming(isCalendarReady.value ? 1 : 0, { duration: 500 }),
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
}));
|
||||
|
||||
const monthStyle = useAnimatedStyle(() => ({
|
||||
opacity: withTiming(mode === 'month' ? 1 : 0, { duration: 300 }),
|
||||
position: 'absolute',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
}));
|
||||
|
||||
const detailedDayStyle = useAnimatedStyle(() => ({
|
||||
opacity: withTiming(mode === 'day' ? 1 : 0, { duration: 300 }),
|
||||
position: 'absolute',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
}));
|
||||
|
||||
const detailedMultiStyle = useAnimatedStyle(() => ({
|
||||
opacity: withTiming(mode === (isTablet ? 'week' : '3days') ? 1 : 0, { duration: 300 }),
|
||||
position: 'absolute',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
}));
|
||||
|
||||
return (
|
||||
<View style={styles.root}>
|
||||
{(isLoading || isSyncing) && (
|
||||
<Animated.View
|
||||
exiting={FadeOut.duration(300)}
|
||||
style={styles.loadingContainer}
|
||||
>
|
||||
{isSyncing && <Text>Syncing...</Text>}
|
||||
<ActivityIndicator size="large" color="#0000ff"/>
|
||||
</Animated.View>
|
||||
)}
|
||||
<Animated.View style={containerStyle}>
|
||||
<Animated.View style={monthStyle} pointerEvents={mode === 'month' ? 'auto' : 'none'}>
|
||||
<MonthCalendar {...props} />
|
||||
</Animated.View>
|
||||
<Animated.View style={detailedDayStyle} pointerEvents={mode === 'day' ? 'auto' : 'none'}>
|
||||
<DetailedCalendar mode="day" {...props} />
|
||||
</Animated.View>
|
||||
<Animated.View style={detailedMultiStyle} pointerEvents={mode === (isTablet ? 'week' : '3days') ? 'auto' : 'none'}>
|
||||
{!isLoading && (
|
||||
<DetailedCalendar onLoad={handleRenderComplete} mode={isTablet ? 'week' : '3days'} {...props} />
|
||||
)}
|
||||
</Animated.View>
|
||||
</Animated.View>
|
||||
</View>
|
||||
);
|
||||
});
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
root: {
|
||||
flex: 1,
|
||||
},
|
||||
loadingContainer: {
|
||||
position: 'absolute',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
zIndex: 100,
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.9)',
|
||||
},
|
||||
|
||||
@ -63,7 +63,7 @@ export const ManuallyAddEventModal = () => {
|
||||
const [editEvent, setEditEvent] = useAtom(eventForEditAtom);
|
||||
const [allDayAtom, setAllDayAtom] = useAtom(isAllDayAtom);
|
||||
const [deleteModalVisible, setDeleteModalVisible] = useState<boolean>(false);
|
||||
const {mutateAsync: deleteEvent, isLoading: isDeleting} = useDeleteEvent();
|
||||
const {mutateAsync: deleteEvent, isPending: isDeleting} = useDeleteEvent();
|
||||
|
||||
const {show, close, initialDate} = {
|
||||
show: !!selectedNewEventDate || !!editEvent,
|
||||
|
||||
@ -37,330 +37,6 @@ const getTotalMinutes = () => {
|
||||
};
|
||||
|
||||
|
||||
const processEventsForSideBySide = (events: CalendarEvent[]) => {
|
||||
if (!events) return [];
|
||||
|
||||
const timeSlots: { [key: string]: CalendarEvent[] } = {};
|
||||
|
||||
events.forEach(event => {
|
||||
const startDate = new Date(event.start);
|
||||
const endDate = new Date(event.end);
|
||||
|
||||
// If it's an all-day event, mark it and add it directly
|
||||
if (event.allDay) {
|
||||
const key = `${startDate.toISOString().split('T')[0]}-allday`;
|
||||
if (!timeSlots[key]) timeSlots[key] = [];
|
||||
timeSlots[key].push({
|
||||
...event,
|
||||
isAllDayEvent: true,
|
||||
allDay: true,
|
||||
width: 1,
|
||||
xPos: 0
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle multi-day events
|
||||
if (startDate.toDateString() !== endDate.toDateString()) {
|
||||
// Create array of dates between start and end
|
||||
const dates = [];
|
||||
let currentDate = new Date(startDate);
|
||||
|
||||
while (currentDate <= endDate) {
|
||||
dates.push(new Date(currentDate));
|
||||
currentDate.setDate(currentDate.getDate() + 1);
|
||||
}
|
||||
|
||||
// Create segments for each day
|
||||
dates.forEach((date, index) => {
|
||||
const isFirstDay = index === 0;
|
||||
const isLastDay = index === dates.length - 1;
|
||||
|
||||
let segmentStart, segmentEnd;
|
||||
|
||||
if (isFirstDay) {
|
||||
// First day: use original start time to end of day
|
||||
segmentStart = new Date(startDate);
|
||||
segmentEnd = new Date(date);
|
||||
segmentEnd.setHours(23, 59, 59);
|
||||
} else if (isLastDay) {
|
||||
// Last day: use start of day to original end time
|
||||
segmentStart = new Date(date);
|
||||
segmentStart.setHours(0, 0, 0);
|
||||
segmentEnd = new Date(endDate);
|
||||
} else {
|
||||
// Middle days: full day
|
||||
segmentStart = new Date(date);
|
||||
segmentStart.setHours(0, 0, 0);
|
||||
segmentEnd = new Date(date);
|
||||
segmentEnd.setHours(23, 59, 59);
|
||||
}
|
||||
|
||||
const key = `${segmentStart.toISOString().split('T')[0]}-${segmentStart.getHours()}`;
|
||||
if (!timeSlots[key]) timeSlots[key] = [];
|
||||
|
||||
timeSlots[key].push({
|
||||
...event,
|
||||
start: segmentStart,
|
||||
end: segmentEnd,
|
||||
isMultiDaySegment: true,
|
||||
isFirstDay,
|
||||
isLastDay,
|
||||
originalStart: startDate,
|
||||
originalEnd: endDate,
|
||||
allDay: true // Mark multi-day events as all-day events
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Regular event
|
||||
const key = `${startDate.toISOString().split('T')[0]}-${startDate.getHours()}`;
|
||||
if (!timeSlots[key]) timeSlots[key] = [];
|
||||
timeSlots[key].push(event);
|
||||
}
|
||||
});
|
||||
|
||||
// Process all time slots
|
||||
return Object.values(timeSlots).flatMap(slotEvents => {
|
||||
// Sort events by start time
|
||||
slotEvents.sort((a, b) => new Date(a.start).getTime() - new Date(b.start).getTime());
|
||||
|
||||
// Find overlapping events (only for non-all-day events)
|
||||
return slotEvents.map((event, index) => {
|
||||
// If it's an all-day or multi-day event, return as is
|
||||
if (event.allDay || event.isMultiDaySegment) {
|
||||
return {
|
||||
...event,
|
||||
width: 1,
|
||||
xPos: 0
|
||||
};
|
||||
}
|
||||
|
||||
// Handle regular events
|
||||
const overlappingEvents = slotEvents.filter((otherEvent, otherIndex) => {
|
||||
if (index === otherIndex || otherEvent.allDay || otherEvent.isMultiDaySegment) return false;
|
||||
const eventStart = new Date(event.start);
|
||||
const eventEnd = new Date(event.end);
|
||||
const otherStart = new Date(otherEvent.start);
|
||||
const otherEnd = new Date(otherEvent.end);
|
||||
return (eventStart < otherEnd && eventEnd > otherStart);
|
||||
});
|
||||
|
||||
const total = overlappingEvents.length + 1;
|
||||
const position = index % total;
|
||||
|
||||
return {
|
||||
...event,
|
||||
width: 1 / total,
|
||||
xPos: position / total
|
||||
};
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const renderEvent = (event: CalendarEvent & {
|
||||
width: number;
|
||||
xPos: number;
|
||||
isMultiDaySegment?: boolean;
|
||||
isFirstDay?: boolean;
|
||||
isLastDay?: boolean;
|
||||
originalStart?: Date;
|
||||
originalEnd?: Date;
|
||||
isAllDayEvent?: boolean;
|
||||
allDay?: boolean;
|
||||
eventColor?: string;
|
||||
attendees?: string[];
|
||||
creatorId?: string;
|
||||
pfp?: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
notes?: string;
|
||||
hideHours?: boolean;
|
||||
}, props: any) => {
|
||||
const {data: familyMembers} = useGetFamilyMembers();
|
||||
|
||||
const attendees = useMemo(() => {
|
||||
if (!familyMembers || !event.attendees) return event?.creatorId ? [event?.creatorId] : [];
|
||||
return familyMembers.filter(member => event?.attendees?.includes(member?.uid!));
|
||||
}, [familyMembers, event.attendees]);
|
||||
|
||||
if (event.allDay && !!event.isMultiDaySegment) {
|
||||
return (
|
||||
<TouchableOpacity
|
||||
{...props}
|
||||
style={[
|
||||
props.style,
|
||||
{
|
||||
width: '100%',
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center'
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Text style={styles.allDayEventText} numberOfLines={1}>
|
||||
{event.title}
|
||||
{event.isMultiDaySegment &&
|
||||
` (${format(new Date(event.start), 'MMM d')} - ${format(new Date(event.end), 'MMM d')})`
|
||||
}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
}
|
||||
|
||||
const originalStyle = Array.isArray(props.style) ? props.style[0] : props.style;
|
||||
|
||||
const startDate = event.start instanceof Date ? event.start : new Date(event.start);
|
||||
const endDate = event.end instanceof Date ? event.end : new Date(event.end);
|
||||
|
||||
const hourHeight = props.hourHeight || 60;
|
||||
const startHour = startDate.getHours();
|
||||
const startMinutes = startDate.getMinutes();
|
||||
const topPosition = (startHour + startMinutes / 60) * hourHeight;
|
||||
|
||||
const endHour = endDate.getHours();
|
||||
const endMinutes = endDate.getMinutes();
|
||||
const duration = (endHour + endMinutes / 60) - (startHour + startMinutes / 60);
|
||||
const height = duration * hourHeight;
|
||||
|
||||
const formatTime = (date: Date) => {
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
const ampm = hours >= 12 ? 'pm' : 'am';
|
||||
const formattedHours = hours % 12 || 12;
|
||||
const formattedMinutes = minutes.toString().padStart(2, '0');
|
||||
return `${formattedHours}:${formattedMinutes}${ampm}`;
|
||||
};
|
||||
|
||||
const timeString = event.isMultiDaySegment
|
||||
? event.isFirstDay
|
||||
? `${formatTime(startDate)} → 12:00PM`
|
||||
: event.isLastDay
|
||||
? `12:00am → ${formatTime(endDate)}`
|
||||
: 'All day'
|
||||
: `${formatTime(startDate)} - ${formatTime(endDate)}`;
|
||||
|
||||
return (
|
||||
<TouchableOpacity
|
||||
{...props}
|
||||
style={[
|
||||
originalStyle,
|
||||
{
|
||||
position: 'absolute',
|
||||
width: `${event.width * 100}%`,
|
||||
left: `${event.xPos * 100}%`,
|
||||
top: topPosition,
|
||||
height: height,
|
||||
zIndex: event.isMultiDaySegment ? 1 : 2,
|
||||
shadowRadius: 2,
|
||||
overflow: "hidden"
|
||||
}
|
||||
]}
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
backgroundColor: event.eventColor,
|
||||
borderRadius: 4,
|
||||
padding: 8,
|
||||
justifyContent: 'space-between'
|
||||
}}
|
||||
>
|
||||
<View>
|
||||
<Text
|
||||
style={{
|
||||
color: 'white',
|
||||
fontSize: 12,
|
||||
fontFamily: "PlusJakartaSans_500Medium",
|
||||
fontWeight: '600',
|
||||
marginBottom: 4
|
||||
}}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{event.title}
|
||||
</Text>
|
||||
<Text
|
||||
style={{
|
||||
color: 'white',
|
||||
fontSize: 10,
|
||||
fontFamily: "PlusJakartaSans_500Medium",
|
||||
opacity: 0.8
|
||||
}}
|
||||
>
|
||||
{timeString}
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
{/* Attendees Section */}
|
||||
{attendees?.length > 0 && (
|
||||
<View style={{flexDirection: 'row', marginTop: 8, height: 27.32}}>
|
||||
{attendees?.filter(x=>x?.firstName).slice(0, 5).map((attendee, index) => (
|
||||
<View
|
||||
key={attendee?.uid}
|
||||
style={{
|
||||
position: 'absolute',
|
||||
left: index * 19,
|
||||
width: 20,
|
||||
height: 20,
|
||||
borderRadius: 50,
|
||||
borderWidth: 2,
|
||||
borderColor: '#f2f2f2',
|
||||
overflow: 'hidden',
|
||||
backgroundColor: attendee.eventColor || colorMap.pink,
|
||||
}}
|
||||
>
|
||||
{attendee.pfp ? (
|
||||
<CachedImage
|
||||
source={{uri: attendee.pfp}}
|
||||
style={{width: '100%', height: '100%'}}
|
||||
cacheKey={attendee.pfp}
|
||||
/>
|
||||
) : (
|
||||
<View style={{
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center'
|
||||
}}>
|
||||
<Text style={{
|
||||
color: 'white',
|
||||
fontSize: 12,
|
||||
fontFamily: "Manrope_600SemiBold",
|
||||
}}>
|
||||
{attendee?.firstName?.at(0)}
|
||||
{attendee?.lastName?.at(0)}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
))}
|
||||
{attendees.length > 3 && (
|
||||
<View style={{
|
||||
position: 'absolute',
|
||||
left: 3 * 19,
|
||||
width: 27.32,
|
||||
height: 27.32,
|
||||
borderRadius: 50,
|
||||
borderWidth: 2,
|
||||
borderColor: '#f2f2f2',
|
||||
backgroundColor: colorMap.pink,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center'
|
||||
}}>
|
||||
<Text style={{
|
||||
color: 'white',
|
||||
fontFamily: "Manrope_600SemiBold",
|
||||
fontSize: 12,
|
||||
}}>
|
||||
+{attendees.length - 3}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
export const MonthCalendar: React.FC<EventCalendarProps> = React.memo(
|
||||
({calendarHeight}) => {
|
||||
const {data: events, isLoading} = useGetEvents();
|
||||
@ -398,12 +74,10 @@ export const MonthCalendar: React.FC<EventCalendarProps> = React.memo(
|
||||
|
||||
const handlePressCell = useCallback(
|
||||
(date: Date) => {
|
||||
if (mode === "day" || mode === "week" || mode === "3days") {
|
||||
setSelectedNewEndDate(date);
|
||||
} else {
|
||||
setMode("day");
|
||||
setSelectedDate(date);
|
||||
}
|
||||
date && setSelectedDate(date);
|
||||
setTimeout(() => {
|
||||
setMode("day");
|
||||
}, 100)
|
||||
},
|
||||
[mode, setSelectedNewEndDate, setSelectedDate]
|
||||
);
|
||||
@ -477,13 +151,11 @@ export const MonthCalendar: React.FC<EventCalendarProps> = React.memo(
|
||||
return {};
|
||||
}
|
||||
}, [mode]);
|
||||
const {enrichedEvents, filteredEvents} = useMemo(() => {
|
||||
const startTime = Date.now();
|
||||
|
||||
const {filteredEvents} = useMemo(() => {
|
||||
const startOffset = mode === "month" ? 40 : (mode === "week" || mode === "3days") ? 10 : 1;
|
||||
const endOffset = mode === "month" ? 40 : (mode === "week" || mode === "3days") ? 10 : 1;
|
||||
|
||||
let eventsToFilter = events;
|
||||
let eventsToFilter = events ?? [];
|
||||
|
||||
if (selectedUser && Device.deviceType === DeviceType.TABLET) {
|
||||
eventsToFilter = events?.filter(event =>
|
||||
@ -495,8 +167,8 @@ export const MonthCalendar: React.FC<EventCalendarProps> = React.memo(
|
||||
const filteredEvents =
|
||||
eventsToFilter?.filter(
|
||||
(event) =>
|
||||
event.start &&
|
||||
event.end &&
|
||||
event?.start instanceof Date &&
|
||||
event?.end instanceof Date &&
|
||||
isWithinInterval(event.start, {
|
||||
start: subDays(selectedDate, startOffset),
|
||||
end: addDays(selectedDate, endOffset),
|
||||
@ -507,83 +179,14 @@ export const MonthCalendar: React.FC<EventCalendarProps> = React.memo(
|
||||
})
|
||||
) ?? [];
|
||||
|
||||
const enrichedEvents = filteredEvents.reduce((acc, event) => {
|
||||
const dateKey = event.start.toISOString().split("T")[0];
|
||||
acc[dateKey] = acc[dateKey] || [];
|
||||
acc[dateKey].push({
|
||||
...event,
|
||||
overlapPosition: false,
|
||||
overlapCount: 0,
|
||||
});
|
||||
|
||||
acc[dateKey].sort((a: { start: any; }, b: { start: any; }) => compareAsc(a.start, b.start));
|
||||
|
||||
return acc;
|
||||
}, {} as Record<string, CalendarEvent[]>);
|
||||
|
||||
const endTime = Date.now();
|
||||
// console.log("memoizedEvents computation time:", endTime - startTime, "ms");
|
||||
|
||||
return {enrichedEvents, filteredEvents};
|
||||
return {filteredEvents};
|
||||
}, [events, selectedDate, mode, selectedUser]);
|
||||
|
||||
const renderCustomDateForMonth = (date: Date) => {
|
||||
const circleStyle = useMemo<ViewStyle>(
|
||||
() => ({
|
||||
width: 30,
|
||||
height: 30,
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
borderRadius: 15,
|
||||
}),
|
||||
[]
|
||||
);
|
||||
|
||||
const defaultStyle = useMemo<ViewStyle>(
|
||||
() => ({
|
||||
...circleStyle,
|
||||
}),
|
||||
[circleStyle]
|
||||
);
|
||||
|
||||
const currentDateStyle = useMemo<ViewStyle>(
|
||||
() => ({
|
||||
...circleStyle,
|
||||
backgroundColor: "#4184f2",
|
||||
}),
|
||||
[circleStyle]
|
||||
);
|
||||
|
||||
const renderDate = useCallback(
|
||||
(date: Date) => {
|
||||
const isCurrentDate = isSameDate(todaysDate, date);
|
||||
const appliedStyle = isCurrentDate ? currentDateStyle : defaultStyle;
|
||||
|
||||
return (
|
||||
<View style={{alignItems: "center"}}>
|
||||
<View style={appliedStyle}>
|
||||
<Text style={{color: isCurrentDate ? "white" : "black"}}>
|
||||
{date.getDate()}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
},
|
||||
[todaysDate, currentDateStyle, defaultStyle]
|
||||
);
|
||||
|
||||
return renderDate(date);
|
||||
};
|
||||
|
||||
const processedEvents = useMemo(() => {
|
||||
return processEventsForSideBySide(filteredEvents);
|
||||
}, [filteredEvents]);
|
||||
|
||||
useEffect(() => {
|
||||
setOffsetMinutes(getTotalMinutes());
|
||||
}, [events, mode]);
|
||||
|
||||
if (isLoading) {
|
||||
if (isLoading || !events) {
|
||||
return (
|
||||
<View style={styles.loadingContainer}>
|
||||
{isSyncing && <Text>Syncing...</Text>}
|
||||
@ -603,7 +206,7 @@ export const MonthCalendar: React.FC<EventCalendarProps> = React.memo(
|
||||
<Calendar
|
||||
bodyContainerStyle={styles.calHeader}
|
||||
swipeEnabled
|
||||
mode={mode}
|
||||
mode={"month"}
|
||||
sortedMonthView
|
||||
events={filteredEvents}
|
||||
// renderEvent={renderEvent}
|
||||
|
||||
@ -29,9 +29,24 @@ interface FormattedEvent {
|
||||
color: string;
|
||||
}
|
||||
|
||||
const createEventHash = (event: FormattedEvent): string => {
|
||||
const startTime = 'date' in event.start ? event.start.date : event.start.dateTime;
|
||||
const endTime = 'date' in event.end ? event.end.date : event.end.dateTime;
|
||||
const str = `${startTime}-${endTime}-${event.title}`;
|
||||
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
const char = str.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + char;
|
||||
hash = hash & hash;
|
||||
}
|
||||
return hash.toString(36);
|
||||
};
|
||||
|
||||
|
||||
// Precompute time constants
|
||||
const DAY_IN_MS = 24 * 60 * 60 * 1000;
|
||||
const PERIOD_IN_MS = 45 * DAY_IN_MS;
|
||||
const PERIOD_IN_MS = 5 * DAY_IN_MS;
|
||||
const TIME_ZONE = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
|
||||
// Memoize date range calculations
|
||||
@ -59,75 +74,70 @@ const getValidDate = (date: any, timestamp?: EventTimestamp): Date | null => {
|
||||
};
|
||||
|
||||
// Batch process events
|
||||
|
||||
const processEvents = async (
|
||||
events: Event[],
|
||||
selectedDate: Date,
|
||||
selectedUser: { uid: string } | null
|
||||
): Promise<FormattedEvent[]> => {
|
||||
// Early return if no events
|
||||
if (!events.length) return [];
|
||||
|
||||
// Pre-calculate constants
|
||||
const currentRangeKey = getDateRangeKey(selectedDate.getTime());
|
||||
const isTablet = Device.deviceType === DeviceType.TABLET;
|
||||
const userId = selectedUser?.uid;
|
||||
|
||||
// Process in chunks to avoid blocking the main thread
|
||||
const uniqueEvents = new Map<string, FormattedEvent>();
|
||||
const processedHashes = new Set<string>();
|
||||
|
||||
const CHUNK_SIZE = 100;
|
||||
const results: FormattedEvent[] = [];
|
||||
|
||||
for (let i = 0; i < events.length; i += CHUNK_SIZE) {
|
||||
const chunk = events.slice(i, i + CHUNK_SIZE);
|
||||
|
||||
// Process chunk and await to give UI thread a chance to breathe
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
|
||||
for (const event of chunk) {
|
||||
try {
|
||||
// Quick user filter
|
||||
if (isTablet && userId &&
|
||||
!event.attendees?.includes(userId) &&
|
||||
event.creatorId !== userId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Validate dates first
|
||||
const startDate = getValidDate(event.start, event.startDate);
|
||||
if (!startDate) continue;
|
||||
|
||||
const rangeKey = getDateRangeKey(startDate.getTime());
|
||||
// Skip events outside our range
|
||||
if (Math.abs(rangeKey - currentRangeKey) > 1) continue;
|
||||
|
||||
const endDate = getValidDate(event.end, event.endDate);
|
||||
if (!endDate) continue;
|
||||
|
||||
if (event.allDay) {
|
||||
const dateStr = format(startDate, 'yyyy-MM-dd');
|
||||
const endDateStr = format(endDate, 'yyyy-MM-dd');
|
||||
const formattedEvent = event.allDay ? {
|
||||
id: event.id,
|
||||
title: event.title,
|
||||
start: { date: format(startDate, 'yyyy-MM-dd') },
|
||||
end: { date: format(endDate, 'yyyy-MM-dd') },
|
||||
color: event.eventColor
|
||||
} : {
|
||||
id: event.id,
|
||||
title: event.title,
|
||||
start: {
|
||||
dateTime: startDate.toISOString(),
|
||||
timeZone: TIME_ZONE
|
||||
},
|
||||
end: {
|
||||
dateTime: endDate.toISOString(),
|
||||
timeZone: TIME_ZONE
|
||||
},
|
||||
color: event.eventColor
|
||||
};
|
||||
|
||||
results.push({
|
||||
id: event.id,
|
||||
title: event.title,
|
||||
start: { date: dateStr },
|
||||
end: { date: endDateStr },
|
||||
color: event.eventColor
|
||||
});
|
||||
} else {
|
||||
results.push({
|
||||
id: event.id,
|
||||
title: event.title,
|
||||
start: {
|
||||
dateTime: startDate.toISOString(),
|
||||
timeZone: TIME_ZONE
|
||||
},
|
||||
end: {
|
||||
dateTime: endDate.toISOString(),
|
||||
timeZone: TIME_ZONE
|
||||
},
|
||||
color: event.eventColor
|
||||
});
|
||||
const hash = createEventHash(formattedEvent);
|
||||
if (!processedHashes.has(hash)) {
|
||||
processedHashes.add(hash);
|
||||
uniqueEvents.set(event.id, formattedEvent);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error processing event:', event.id, error);
|
||||
continue;
|
||||
@ -135,7 +145,7 @@ const processEvents = async (
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
return Array.from(uniqueEvents.values());
|
||||
};
|
||||
|
||||
export const useFormattedEvents = (
|
||||
|
||||
@ -79,7 +79,6 @@ const GroceryItem = ({
|
||||
setTitle: setNewTitle,
|
||||
setCategory: setCategory,
|
||||
closeEdit: closeEdit,
|
||||
handleEditSubmit: updateGroceryItem,
|
||||
}}
|
||||
onInputFocus={onInputFocus}
|
||||
/>
|
||||
|
||||
@ -107,9 +107,6 @@ const HeaderTemplate = (props: {
|
||||
{isFamilyView && props.isCalendar && children.length > 0 && (
|
||||
<View style={styles.childrenPfpArr} row>
|
||||
{children.slice(0, 3).map((child, index) => {
|
||||
{
|
||||
console.log("yeaaaah");
|
||||
}
|
||||
const bgColor: string = child.eventColor || colorMap.pink;
|
||||
return child.pfp ? (
|
||||
<Image
|
||||
@ -162,9 +159,6 @@ const HeaderTemplate = (props: {
|
||||
{isFamilyView && props.isCalendar && children.length > 0 && (
|
||||
<View style={styles.childrenPfpArr} row>
|
||||
{children.slice(0, 3).map((child, index) => {
|
||||
{
|
||||
console.log("yeaaaah");
|
||||
}
|
||||
const bgColor: string = child.eventColor || colorMap.pink;
|
||||
return child.pfp ? (
|
||||
<Image
|
||||
|
||||
Reference in New Issue
Block a user