react-schedule-selector icon indicating copy to clipboard operation
react-schedule-selector copied to clipboard

Possible Bug with Duplicated Dates on Drag Selection

Open nktnet1 opened this issue 3 years ago • 0 comments

Hi,

I believe there's an issue with the dates being duplicated in the date array passed into "onChange". This can be reproduced by:

  1. Select a cell (e.g. Cell A).
  2. Click an unselected cell (e.g. Cell B) and simultaneously drag it onto the selected Cell A.

Array will contain ["Cell A", "Cell B", "Cell A"].

Problem reproducible in sandbox: https://codesandbox.io/s/objective-pateu-y8lr0?file=/src/App.js

Currently using the following as a temporary workaround:

  const [schedule, setSchedule] = React.useState([])

  // ...

  const handleChange = (newSchedule) => {
    // setSchedule(schedule) // has duplicates - below will filter date to be unique.
    setSchedule([...new Set(schedule.map(date => +date))].map(timestamp => new Date(timestamp)));
  }

Thanks :) - Really appreciate your work!

nktnet1 avatar Jan 12 '22 06:01 nktnet1