import React from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import classNames from 'classnames';
import {
DragDropContext,
Droppable,
Draggable
} from 'react-beautiful-dnd';
import uid from 'uuid/v4';
import {
Card,
CardHeader,
CardTitle,
Avatar,
AvatarAddOn
} from './../../../../components';
import { randomAvatar, randomArray } from './../../../../utilities';
import { reorder, move } from './utilities';
import classes from './common.scss';
const generateItem = () => ({
id: uid(),
avatarUrl: randomAvatar(),
status: randomArray(['success', 'warning', 'danger'])
});
const getListClass = (isDraggedOver) =>
classNames(classes['list'], {
[classes['list--drag-over']]: isDraggedOver
});
const RowList = (props) => (
{ props.title }
{(provided, snapshot) => (
{_.map(props.items, (item, index) => (
{(provided) => (
)}
))}
{ provided.placeholder }
)}
)
RowList.propTypes = {
listId: PropTypes.string.isRequired,
items: PropTypes.array.isRequired,
title: PropTypes.string.isRequired,
className: PropTypes.stirng
}
const initialState = {
listAItems: _.times(_.random(3, 8), generateItem),
listBItems: _.times(_.random(3, 8), generateItem),
listCItems: _.times(_.random(3, 8), generateItem)
};
export class HorizontalLists extends React.Component {
static propTypes = {
className: PropTypes.string
}
state = _.clone(initialState);
constructor (props) {
super(props);
this.onDragEnd = this.onDragEnd.bind(this);
}
onDragEnd(result) {
const { source, destination } = result;
// dropped outside the list
if (!destination) {
return;
}
// Handle List Items
if (source.droppableId === destination.droppableId) {
const items = reorder(
this.state[`${source.droppableId}Items`],
source.index,
destination.index
);
this.setState({
[`${source.droppableId}Items`]: items
});
} else {
const result = move(
this.state[`${source.droppableId}Items`],
this.state[`${destination.droppableId}Items`],
source,
destination
);
this.setState(_.mapKeys(result, (val, key) => `${key}Items`));
}
}
recoverInitialState() {
this.setState(initialState);
}
render() {
const { className } = this.props;
return (
)
}
}