| | |
| | | import ItemTypes from './itemtypes' |
| | | import './index.scss' |
| | | |
| | | const Container = ({list, setting, placeholder, handleList, handleForm, closeForm }) => { |
| | | const Container = ({list, group, setting, placeholder, handleList, handleForm, closeForm }) => { |
| | | let target = null |
| | | |
| | | const [cards, setCards] = useState(list) |
| | | const moveCard = (id, atIndex) => { |
| | | const { card, index } = findCard(id) |
| | | |
| | | if (!card) return |
| | | |
| | | const _cards = update(cards, { $splice: [[index, 1], [atIndex, 0, card]] }) |
| | | setCards(_cards) |
| | | handleList(_cards) |
| | | if (!group) { |
| | | handleList(_cards) |
| | | } else { |
| | | handleList(_cards, group) |
| | | } |
| | | } |
| | | |
| | | const findCard = id => { |
| | |
| | | const [, drop] = useDrop({ |
| | | accept: ItemTypes.form, |
| | | drop(item) { |
| | | if (item.hasOwnProperty('originalIndex') && group) { |
| | | const { card } = findCard(item.id) |
| | | |
| | | if (!card) { |
| | | handleList(cards, group, item.id) |
| | | } |
| | | } |
| | | if (item.hasOwnProperty('originalIndex')) { |
| | | return |
| | | } |
| | |
| | | newcard.orderBy = '' |
| | | newcard.orderType = 'asc' |
| | | |
| | | let indexes = cards.map(car => {return car.id}) |
| | | let newid = 0 |
| | | while (indexes.includes(newid)) { |
| | | newid++ |
| | | } |
| | | newcard.id = newid |
| | | // let indexes = cards.map(car => {return car.id}) |
| | | // let newid = 0 |
| | | // while (indexes.includes(newid)) { |
| | | // newid++ |
| | | // } |
| | | newcard.id = Utils.getuuid() |
| | | |
| | | let targetId = indexes.length > 0 ? indexes[indexes.length - 1] : 0 |
| | | let targetId = cards.length > 0 ? cards[cards.length - 1].id : 0 |
| | | if (target) { |
| | | targetId = target.id |
| | | } |
| | |
| | | |
| | | const _cards = update(cards, { $splice: [[targetIndex, 0, newcard]] }) |
| | | setCards(_cards) |
| | | handleList(_cards) |
| | | |
| | | if (!group) { |
| | | handleList(_cards) |
| | | } else { |
| | | handleList(_cards, group) |
| | | } |
| | | |
| | | target = null |
| | | } |
| | | }) |