bibekg / react-schedule-selector

A mobile-friendly when2meet-style grid-based schedule selector
MIT License
147 stars 51 forks source link

Possible Bug with Duplicated Dates on Drag Selection #52

Open nktnet1 opened 2 years ago

nktnet1 commented 2 years ago

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!