Skip to content

Commit

Permalink
refactor: manual ordering bugs (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryan610 authored Feb 21, 2023
1 parent 8c15a15 commit 8d6a357
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
4 changes: 2 additions & 2 deletions apps/app/components/core/board-view/single-board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const SingleBoard: React.FC<Props> = ({
<StrictModeDroppable key={groupTitle} droppableId={groupTitle}>
{(provided, snapshot) => (
<div
className={`relative mt-3 h-full space-y-3 px-3 pb-3 ${
className={`relative mt-3 h-full px-3 pb-3 ${
snapshot.isDraggingOver ? "bg-indigo-50 bg-opacity-50" : ""
} ${!isCollapsed ? "hidden" : "block"}`}
ref={provided.innerRef}
Expand All @@ -104,7 +104,7 @@ export const SingleBoard: React.FC<Props> = ({
snapshot.isDraggingOver ? "block" : "hidden"
} top-1/2 left-1/2 -translate-y-1/2 -translate-x-1/2 text-xs whitespace-nowrap bg-white p-2 rounded pointer-events-none z-[99999999]`}
>
This board is order by {orderBy}
This board is ordered by {orderBy}
</div>
</>
)}
Expand Down
2 changes: 1 addition & 1 deletion apps/app/components/core/board-view/single-issue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export const SingleBoardIssue: React.FC<Props> = ({

return (
<div
className={`rounded border bg-white shadow-sm ${
className={`rounded border bg-white shadow-sm mb-3 ${
snapshot.isDragging ? "border-theme bg-indigo-50 shadow-lg" : ""
}`}
ref={provided.innerRef}
Expand Down
49 changes: 35 additions & 14 deletions apps/app/components/core/issues-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,41 @@ export const IssuesView: React.FC<Props> = ({
const destinationGroupArray = groupedByIssues[destination.droppableId];

if (destinationGroupArray.length !== 0) {
if (destination.index === 0) newSortOrder = destinationGroupArray[0].sort_order - 10000;
else if (
(source.droppableId !== destination.droppableId &&
destination.index === destinationGroupArray.length) ||
(source.droppableId === destination.droppableId &&
destination.index === destinationGroupArray.length - 1)
)
newSortOrder =
destinationGroupArray[destinationGroupArray.length - 1].sort_order + 10000;
else
newSortOrder =
(destinationGroupArray[destination.index - 1].sort_order +
destinationGroupArray[destination.index].sort_order) /
2;
// check if dropping in the same group
if (source.droppableId === destination.droppableId) {
// check if dropping at beginning
if (destination.index === 0)
newSortOrder = destinationGroupArray[0].sort_order - 10000;
// check if dropping at last
else if (destination.index === destinationGroupArray.length - 1)
newSortOrder =
destinationGroupArray[destinationGroupArray.length - 1].sort_order + 10000;
else {
if (destination.index > source.index)
newSortOrder =
(destinationGroupArray[source.index + 1].sort_order +
destinationGroupArray[source.index + 2].sort_order) /
2;
else if (destination.index < source.index)
newSortOrder =
(destinationGroupArray[source.index - 1].sort_order +
destinationGroupArray[source.index - 2].sort_order) /
2;
}
} else {
// check if dropping at beginning
if (destination.index === 0)
newSortOrder = destinationGroupArray[0].sort_order - 10000;
// check if dropping at last
else if (destination.index === destinationGroupArray.length)
newSortOrder =
destinationGroupArray[destinationGroupArray.length - 1].sort_order + 10000;
else
newSortOrder =
(destinationGroupArray[destination.index - 1].sort_order +
destinationGroupArray[destination.index].sort_order) /
2;
}
}

draggedItem.sort_order = newSortOrder;
Expand Down

1 comment on commit 8d6a357

@vercel
Copy link

@vercel vercel bot commented on 8d6a357 Feb 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

plane-dev – ./apps/app

plane-dev.vercel.app
plane-dev-git-develop-caravel.vercel.app
plane-dev-caravel.vercel.app

Please sign in to comment.