fix: get correct new postion after dropping task in different list

was getting the current draggable list based on whatever task group
the task was in, ignoring that that task group might be different (when
    the task was dragged to a new list)
This commit is contained in:
Jordan Knott 2020-08-12 15:17:44 -05:00
parent 2e9767f1a0
commit 7bba294897
3 changed files with 11 additions and 4 deletions

View File

@ -396,6 +396,7 @@ const ProjectBoard: React.FC<ProjectBoardProps> = ({ projectID, onCardLabelClick
__typename: 'UpdateTaskLocationPayload', __typename: 'UpdateTaskLocationPayload',
previousTaskGroupID, previousTaskGroupID,
task: { task: {
...droppedTask,
__typename: 'Task', __typename: 'Task',
name: droppedTask.name, name: droppedTask.name,
id: droppedTask.id, id: droppedTask.id,

View File

@ -39,6 +39,7 @@ type Props = {
taskID: string; taskID: string;
taskGroupID: string; taskGroupID: string;
complete?: boolean; complete?: boolean;
position?: string | number;
onContextMenu?: ($target: React.RefObject<HTMLElement>, taskID: string, taskGroupID: string) => void; onContextMenu?: ($target: React.RefObject<HTMLElement>, taskID: string, taskGroupID: string) => void;
onClick?: (e: React.MouseEvent<HTMLDivElement>) => void; onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
description?: null | string; description?: null | string;
@ -76,6 +77,7 @@ const Card = React.forwardRef(
dueDate, dueDate,
description, description,
checklists, checklists,
position,
watched, watched,
members, members,
labelVariant, labelVariant,
@ -205,7 +207,7 @@ const Card = React.forwardRef(
) : ( ) : (
<CardTitle> <CardTitle>
{complete && <CompleteIcon width={16} height={16} />} {complete && <CompleteIcon width={16} height={16} />}
{title} {`${title}${position ? ' - ' + position : ''}`}
</CardTitle> </CardTitle>
)} )}
<ListCardBadges> <ListCardBadges>

View File

@ -84,10 +84,14 @@ const SimpleLists: React.FC<SimpleProps> = ({
throw { error: 'task group can not be found' }; throw { error: 'task group can not be found' };
} }
} else { } else {
const targetGroup = taskGroups.findIndex( const curTaskGroup = taskGroups.findIndex(
taskGroup => taskGroup.tasks.findIndex(task => task.id === draggableId) !== -1, taskGroup => taskGroup.tasks.findIndex(task => task.id === draggableId) !== -1,
); );
const droppedTask = taskGroups[targetGroup].tasks.find(task => task.id === draggableId); let targetTaskGroup = curTaskGroup;
if (!isSameList) {
targetTaskGroup = taskGroups.findIndex(taskGroup => taskGroup.id === destination.droppableId);
}
const droppedTask = taskGroups[curTaskGroup].tasks.find(task => task.id === draggableId);
if (droppedTask) { if (droppedTask) {
droppedDraggable = { droppedDraggable = {
@ -95,7 +99,7 @@ const SimpleLists: React.FC<SimpleProps> = ({
position: droppedTask.position, position: droppedTask.position,
}; };
beforeDropDraggables = getSortedDraggables( beforeDropDraggables = getSortedDraggables(
taskGroups[targetGroup].tasks.map(task => { taskGroups[targetTaskGroup].tasks.map(task => {
return { id: task.id, position: task.position }; return { id: task.id, position: task.position };
}), }),
); );