Skip to content

Items removed and camback when i multilpe drag sort #2460

@nguyenthanhcong101096

Description

@nguyenthanhcong101096

I deleted a lot of items. Then I moved some items up. However the items that were moved were not the items I had selected, they were the items I had deleted and they came back again

I using react and sortablejs@1.15.7

  const updatePosition = () => {
    if (!sortableRef.current) return
    let ids = sortableRef.current.toArray()
    setImages((images) => {
      return sortBy(images, [
        (image) => {
          const index = ids.findIndex((id) => Number(id) === Number(image.id))
          return typeof index === 'number' ? index : 9999
        },
      ])
    })
  }

  useEffect(() => {
    updateFormikField()
    if (typeof setOuterPhotos === 'function') {
      setOuterPhotos(images)
    }
    if (isSingle) return
    if (!sortableRef.current && !viewMode) {
      sortableRef.current = new Sortable(sortableEleRef.current, {
        multiDrag: true,
        selectedClass: 'sortable-selected',
        onEnd: updatePosition
      })
    }

    updatePosition()
  }, [images.map((o) => o.id).join(',')])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions