mirror of
https://github.com/urosran/cally.git
synced 2025-07-17 10:35:08 +00:00
Event filtering
This commit is contained in:
@ -13,6 +13,7 @@ import {
|
|||||||
import { useAuthContext } from "@/contexts/AuthContext";
|
import { useAuthContext } from "@/contexts/AuthContext";
|
||||||
import { CalendarEvent } from "@/components/pages/calendar/interfaces";
|
import { CalendarEvent } from "@/components/pages/calendar/interfaces";
|
||||||
import { Text } from "react-native-ui-lib";
|
import { Text } from "react-native-ui-lib";
|
||||||
|
import {addDays, isWithinInterval, subDays} from "date-fns";
|
||||||
|
|
||||||
interface EventCalendarProps {
|
interface EventCalendarProps {
|
||||||
calendarHeight: number;
|
calendarHeight: number;
|
||||||
@ -46,7 +47,7 @@ export const EventCalendar: React.FC<EventCalendarProps> = React.memo(
|
|||||||
setIsRendering(true);
|
setIsRendering(true);
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
setIsRendering(false);
|
setIsRendering(false);
|
||||||
}, 300);
|
}, 10 );
|
||||||
return () => clearTimeout(timeout);
|
return () => clearTimeout(timeout);
|
||||||
}
|
}
|
||||||
}, [events, mode]);
|
}, [events, mode]);
|
||||||
@ -125,7 +126,16 @@ export const EventCalendar: React.FC<EventCalendarProps> = React.memo(
|
|||||||
}
|
}
|
||||||
}, [mode]);
|
}, [mode]);
|
||||||
|
|
||||||
const memoizedEvents = useMemo(() => events ?? [], [events]);
|
const memoizedEvents = useMemo(() => {
|
||||||
|
const startOffset = mode === "month" ? 40 : mode === "week" ? 10 : 1;
|
||||||
|
const endOffset = mode === "month" ? 40 : mode === "week" ? 10 : 1;
|
||||||
|
|
||||||
|
return events?.filter(event =>
|
||||||
|
event.start && event.end &&
|
||||||
|
isWithinInterval(event.start, { start: subDays(selectedDate, startOffset), end: addDays(selectedDate, endOffset) }) &&
|
||||||
|
isWithinInterval(event.end, { start: subDays(selectedDate, startOffset), end: addDays(selectedDate, endOffset) })
|
||||||
|
) ?? [];
|
||||||
|
}, [events, selectedDate, mode]);
|
||||||
|
|
||||||
const renderCustomDateForMonth = (date: Date) => {
|
const renderCustomDateForMonth = (date: Date) => {
|
||||||
const circleStyle = useMemo<ViewStyle>(
|
const circleStyle = useMemo<ViewStyle>(
|
||||||
|
@ -30,13 +30,12 @@ exports.sendNotificationOnEventCreation = functions.firestore
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pushTokens.length) {
|
let pushTokens = await getPushTokensForFamilyExcludingCreator(familyId, creatorId);
|
||||||
pushTokens = await getPushTokensForFamilyExcludingCreator(familyId, creatorId);
|
|
||||||
if (!pushTokens.length) {
|
if (!pushTokens.length) {
|
||||||
console.log('No push tokens available for the event.');
|
console.log('No push tokens available for the event.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
eventCount++;
|
eventCount++;
|
||||||
|
|
||||||
@ -49,21 +48,20 @@ exports.sendNotificationOnEventCreation = functions.firestore
|
|||||||
? `An event "${eventData.title}" has been added. Check it out!`
|
? `An event "${eventData.title}" has been added. Check it out!`
|
||||||
: `${eventCount} new events have been added.`;
|
: `${eventCount} new events have been added.`;
|
||||||
|
|
||||||
let messages = [];
|
let messages = pushTokens.map(pushToken => {
|
||||||
for (let pushToken of pushTokens) {
|
|
||||||
if (!Expo.isExpoPushToken(pushToken)) {
|
if (!Expo.isExpoPushToken(pushToken)) {
|
||||||
console.error(`Push token ${pushToken} is not a valid Expo push token`);
|
console.error(`Push token ${pushToken} is not a valid Expo push token`);
|
||||||
continue;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
messages.push({
|
return {
|
||||||
to: pushToken,
|
to: pushToken,
|
||||||
sound: 'default',
|
sound: 'default',
|
||||||
title: 'New Events Added!',
|
title: 'New Events Added!',
|
||||||
body: eventMessage,
|
body: eventMessage,
|
||||||
data: { eventId: context.params.eventId },
|
data: { eventId: context.params.eventId },
|
||||||
});
|
};
|
||||||
}
|
}).filter(Boolean);
|
||||||
|
|
||||||
let chunks = expo.chunkPushNotifications(messages);
|
let chunks = expo.chunkPushNotifications(messages);
|
||||||
let tickets = [];
|
let tickets = [];
|
||||||
@ -78,7 +76,7 @@ exports.sendNotificationOnEventCreation = functions.firestore
|
|||||||
console.log('Notification successfully sent:', ticket.id);
|
console.log('Notification successfully sent:', ticket.id);
|
||||||
} else if (ticket.status === 'error') {
|
} else if (ticket.status === 'error') {
|
||||||
console.error(`Notification error: ${ticket.message}`);
|
console.error(`Notification error: ${ticket.message}`);
|
||||||
if (ticket.details && ticket.details.error === 'DeviceNotRegistered') {
|
if (ticket.details?.error === 'DeviceNotRegistered') {
|
||||||
await removeInvalidPushToken(ticket.to);
|
await removeInvalidPushToken(ticket.to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,8 +86,8 @@ exports.sendNotificationOnEventCreation = functions.firestore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eventCount = 0; // Reset the event count after sending notification
|
eventCount = 0;
|
||||||
pushTokens = []; // Reset push tokens for the next round
|
pushTokens = [];
|
||||||
|
|
||||||
}, 5000);
|
}, 5000);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user