namespace-ee / react-calendar-timeline

A modern and responsive react timeline component.
MIT License
1.93k stars 625 forks source link

onTimeChange called before onItemDrag #838

Open atheck opened 2 years ago

atheck commented 2 years ago

Describe the bug

When dragging an item, onTimeChange is called just before onItemDrag. This happens only randomly.

In my case this unnecessarily causes reloading of data. When this happens, the moved item gets "recreated" and jumps back to the start position before dragging.

To Reproduce

<Timeline
    groups={groups}
    items={items}
    onItemDrag={() => console.log("onItemDrag")}
    onTimeChange={() => console.log("onTimeChange")}
/>

Sometimes this will print:

onTimeChange
onItemDrag

Expected behavior

onTimeChange should not be called before dragging an item.

Library Version

"react-calendar-timeline": "0.27.0"

Desktop (please complete the following information):

Ilaiwi commented 2 years ago

@atheck this happens because how the library is implemented it's hard to distinguish between a select and drag an item vs dragging the timeline to scroll. Please feel free to submit a PR with a fix for this issue.

tejastomarbyte commented 2 years ago

I would like to fix this issue, but I am just starting with open source. Can someone please guide on this ?

pancholipratham7 commented 2 years ago

Hey I want to contribute to this issue can you please assign this task to me

DanielDerma commented 1 year ago

i made a solution: PR: #893

ShabinMuhammedKK commented 3 weeks ago

Add conditions to trigger onTimeChange only when there's a meaningful change in the timeline (i.e., not during a drag)

const handleTimeChange = () => { if (!isDragging) { console.log("onTimeChange"); } };

<Timeline groups={groups} items={items} onItemDrag={() => { setIsDragging(true); console.log("onItemDrag"); }} onTimeChange={handleTimeChange} />