Apple calendar sync, timezone, first day of week additions

This commit is contained in:
Milan Paunovic
2024-10-19 22:56:55 +02:00
parent 00b6225a1c
commit 3653400a92
25 changed files with 1154 additions and 689 deletions
@@ -0,0 +1,41 @@
import * as Calendar from 'expo-calendar';
export async function fetchiPhoneCalendarEvents(familyId, email, startDate, endDate) {
try {
const {status} = await Calendar.requestCalendarPermissionsAsync();
if (status !== 'granted') {
throw new Error("Calendar permission not granted");
}
const defaultCalendarSource = await Calendar.getDefaultCalendarAsync();
if (!defaultCalendarSource) {
throw new Error("No calendar found");
}
const events = await Calendar.getEventsAsync(
[defaultCalendarSource.id],
startDate,
endDate
);
return events.map((event) => {
let isAllDay = event.allDay || false;
const startDateTime = new Date(event.startDate);
const endDateTime = new Date(event.endDate);
return {
id: event.id,
title: event.title,
startDate: startDateTime,
endDate: endDateTime,
allDay: isAllDay,
familyId,
email
};
});
} catch (error) {
console.error("Error fetching iPhone Calendar events: ", error);
throw error;
}
}
@@ -1,4 +1,4 @@
export async function fetchGoogleCalendarEvents(token, email, startDate, endDate) {
export async function fetchGoogleCalendarEvents(token, email, familyId, startDate, endDate) {
console.log(token);
const response = await fetch(
`https://www.googleapis.com/calendar/v3/calendars/primary/events?single_events=true&time_min=${startDate}&time_max=${endDate}`,
@@ -45,6 +45,7 @@ export async function fetchGoogleCalendarEvents(token, email, startDate, endDate
startDate: startDateTime,
endDate: endDateTime,
allDay: isAllDay,
familyId,
email
};
googleEvents.push(googleEvent);
@@ -1,4 +1,4 @@
export async function fetchMicrosoftCalendarEvents(token, email, startDate, endDate) {
export async function fetchMicrosoftCalendarEvents(token, email, familyId, startDate, endDate) {
const response = await fetch(
`https://graph.microsoft.com/v1.0/me/calendar/calendarView?startDateTime=${startDate}&endDateTime=${endDate}`,
{
@@ -34,6 +34,7 @@ export async function fetchMicrosoftCalendarEvents(token, email, startDate, endD
startDate: startDateTime,
endDate: endDateTime,
allDay: item.isAllDay,
familyId,
email
};