From 68f21633656d75222647fcacf76280b4e6d67b5b Mon Sep 17 00:00:00 2001 From: Joel Jeremy Marquez Date: Sat, 20 Jan 2024 15:56:26 -0800 Subject: [PATCH] Sortable mobile accounts --- .../components/accounts/MobileAccounts.jsx | 158 +++++++++++++++--- .../src/components/sidebar/Account.tsx | 1 - 2 files changed, 135 insertions(+), 24 deletions(-) diff --git a/packages/desktop-client/src/components/accounts/MobileAccounts.jsx b/packages/desktop-client/src/components/accounts/MobileAccounts.jsx index 158dbec52fa..731466ca6eb 100644 --- a/packages/desktop-client/src/components/accounts/MobileAccounts.jsx +++ b/packages/desktop-client/src/components/accounts/MobileAccounts.jsx @@ -1,7 +1,27 @@ import React, { useEffect, useState } from 'react'; import { useSelector } from 'react-redux'; +import { + DndContext, + MouseSensor, + TouchSensor, + closestCenter, + useSensor, + useSensors, +} from '@dnd-kit/core'; +import { + restrictToParentElement, + restrictToVerticalAxis, +} from '@dnd-kit/modifiers'; +import { + SortableContext, + useSortable, + verticalListSortingStrategy, +} from '@dnd-kit/sortable'; +import { CSS } from '@dnd-kit/utilities'; + import * as queries from 'loot-core/src/client/queries'; +import { send } from 'loot-core/src/platform/client/fetch'; import { useActions } from '../../hooks/useActions'; import { useCategories } from '../../hooks/useCategories'; @@ -16,6 +36,7 @@ import { View } from '../common/View'; import { Page } from '../Page'; import { PullToRefresh } from '../responsive/PullToRefresh'; import { CellValue } from '../spreadsheet/CellValue'; +import { findSortDown, getDropPosition } from '../util/sort'; function AccountHeader({ name, amount, style = {} }) { return ( @@ -52,8 +73,26 @@ function AccountHeader({ name, amount, style = {} }) { } function AccountCard({ account, updated, getBalanceQuery, onSelect }) { + const { + isDragging, + attributes, + listeners, + setNodeRef, + transform, + transition, + } = useSortable({ id: account.id }); + + const dndStyle = { + opacity: isDragging ? 0.5 : undefined, + transform: CSS.Transform.toString(transform), + transition, + }; + return (