Skip to content

Commit

Permalink
Remove Group: text when sorting groups + use onDragOver
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Jan 20, 2024
1 parent 34e7a80 commit 05d338a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
27 changes: 13 additions & 14 deletions packages/desktop-client/src/components/budget/BudgetCategories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
useSensor,
useSensors,
} from '@dnd-kit/core';
import { restrictToParentElement, restrictToVerticalAxis } from '@dnd-kit/modifiers';
import {
restrictToParentElement,
restrictToVerticalAxis,
} from '@dnd-kit/modifiers';
import {
SortableContext,
sortableKeyboardCoordinates,
Expand Down Expand Up @@ -168,7 +171,7 @@ export const BudgetCategories = memo(
);

const [originalCollapsed, setOriginalCollapsed] = useState(null);
const [collapsedOnDragMove, setCollapsedOnDragMove] = useState(null);
const [collapsedOnDragOver, setCollapsedOnDragOver] = useState(null);

const onDragStart = e => {
const { active } = e;
Expand All @@ -181,24 +184,20 @@ export const BudgetCategories = memo(
.filter(item => item.type === 'expense-group')
.map(item => item.value?.id);

setCollapsedOnDragMove(groupIds);
setCollapsedOnDragOver(groupIds);
break;
default:
break;
}
};

const onDragMove = e => {
const onDragOver = e => {
const { active, over } = e;

if (!over) {
return;
}

// Delay collapsing groups until user moves the group.
if (collapsedOnDragMove) {
setCollapsed(collapsedOnDragMove);
setCollapsedOnDragMove(null);
// Delay collapsing groups until user drags/hovers on another item.
if (collapsedOnDragOver) {
setCollapsed(collapsedOnDragOver);
setCollapsedOnDragOver(null);
}

// Expand groups on hover when moving around categories.
Expand Down Expand Up @@ -262,7 +261,7 @@ export const BudgetCategories = memo(
collisionDetection={closestCenter}
modifiers={[restrictToVerticalAxis, restrictToParentElement]}
onDragStart={onDragStart}
onDragMove={onDragMove}
onDragOver={onDragOver}
onDragEnd={onDragEnd}
>
<SortableContext
Expand Down Expand Up @@ -367,7 +366,7 @@ export const BudgetCategories = memo(
collisionDetection={closestCenter}
modifiers={[restrictToVerticalAxis, restrictToParentElement]}
onDragStart={onDragStart}
onDragMove={onDragMove}
onDragOver={onDragOver}
onDragEnd={onDragEnd}
>
<SortableContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export function SidebarGroup({
minWidth: 0,
}}
>
{dragPreview && <Text style={{ fontWeight: 500 }}>Group: </Text>}
{group.name}
</div>
{!dragPreview && (
Expand Down

0 comments on commit 05d338a

Please sign in to comment.