Expo Calendar Creating and Tracking Events

935 Views Asked by At

I am having a seriously tough time figuring out how to effectively manage events created with .createEventAsync() method in expo-calendar API. Docs found here. This is the structure of the parameter I am entering into .createEventAsync().

testEvent = {
  calendarId: calendarId,
  title: event.position,
  startDate: shiftStart,
  endDate: shiftEnd,
  location: event.store.name,
  alarms: [],
  id: event.id,
}

The idea is to have the event id on the app calendar be the same as the id on the OS calendar, but it seems like that is not possible. I am trying to build a system that requests permissions, if permissions granted then sync all events on the app with the os calendar. If the event already exists, do not create another event.

The function runs a check with:

async function checkEventExists(eventId: any) {
  try {
    const event = await Calendar.getEventAsync(eventId)
    console.log(console.log(event))
    if (event) {
      return true
    }
  } catch {
    return false
  }
}

If false, event is not created. If true then .createEventAsync() is called.

Currently, new instances of the same event are created every time the app polls data from the server and this is unrelated, but also creates 7 instances of 1 event each time data is polled. How do people usually manage and track calendar events after creation? I thought event id would be a good way to tell if the event is one and the same, but I was wrong.

0

There are 0 best solutions below