import React, { Component } from 'react';
import { SortableContainer, SortableElement } from 'react-sortable-hoc';
import { arrayMoveImmutable } from 'array-move';
import { Card, Button } from 'antd';
import { ImgGood } from '.';
const SortableItem = SortableElement(({ value: { _id, url, onSave } }) =>
);
const SortableList = SortableContainer(({ items, idGood, onSave, onChangeImagesOnSer }) => {
return (
<>
{items.map((value, index) => (
onSave(value._id)
}
} />
))}
>
);
});
class SortableComponent extends Component {
state = {
items: this.props.images,
idGood: this.props.idGood,
clearUpLoad: this.props.clearUpLoad
};
getState =() => console.log('this.state', this.state)
onSortEnd = ({ oldIndex, newIndex }) => {
this.setState(({ items }) => ({
items: arrayMoveImmutable(items, oldIndex, newIndex)
}));
this.getState();
};
onChangeImagesOnSer = () => {
const arrImagesForSave = this.state.items.map((item) => ({ _id: item._id }));
this.props.onChangeArrInGood(this.state.idGood, arrImagesForSave);
}
onSave = (idImg) => {
const newArrImgs = this.state.items.map((item) => {
if (idImg === item._id) {
return {
_id: this.props.upLoad._id,
url: this.props.upLoad.url
};
};
return item;
});
this.setState(() => ({ items: newArrImgs }));
this.state.clearUpLoad();
}
render () {
return (
);
}
}
export default SortableComponent;