Async Methods to create event

Hi there,

I am just looking for an option to create an event based on some async operations in the timeline view after drag drop.

The idea is to have a prompt taking user action to allow drop. Right now only passing false prevents the drag but I need an async method to handle it.

I have a complex calculation and cannot setstate and filter data as it can be expensive.

      onEventCreate={async (event) => {
            return await addEventToMap(event);
          }}

Regards,

Hi @Kashan_Saleem

So, are you dragging an event from an external list into the event calendar? Just trying to understand the workflow a bit better. Could you explain the use case in more detail? Also, could you share some more of your current code how you’re trying this?

Thanks!

Hi,
As per this example two-synchronized-timelines I want to take some confirmation from user and also need to show some warnings before allowing to drop event to other timeline.

Thnks.

Hi @Kashan_Saleem

I’ve tried the demo you mentioned. My idea is to create the event using the async function (where the event is passed as a parameter) and immediately return false right after the async call. Here’s the sample I tried in that demo:

const handleEventCreate = useCallback((args) => {
    // async operation, simulating 1000ms delay
    const createEvent = async (event) => {
      await new Promise((resolve) => setTimeout(resolve, 1000));
      setFlights((current) => [...current, event]);
    };
    createEvent(args.event);
    // return false to prevent the default behavior, creating the event immediately
    return false;
  }, []);

Let me know your thoughts on this approach.

Hi,

Thank you for the solution. I am already following a similar approach, but my issue is that I don’t want to use setFlights, as I am performing complex calculations to display overlapping flights and other computations that I prefer not to re-run.

Since I can drag and drop in both timelines, I would need to maintain two separate states and additional calculations which is not preferable.

However, this could be solved easily if a built-in async method existed.

Hi @Kashan_Saleem

Thanks for the feedback! There isn’t any built-in way to use async in onEventCreate like the example you shared initially. Apologies, but I still don’t see the complete flow of what’s happening. Could you share more details about the heavy calculations and the overall flow?