fix: restore drag-and-drop in ContactFolderTree with dropdown menu (rename/color/pin/delete)
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
useCreateContactFolder,
|
useCreateContactFolder,
|
||||||
useUpdateContactFolder,
|
useUpdateContactFolder,
|
||||||
useDeleteContactFolder,
|
useDeleteContactFolder,
|
||||||
|
useMoveContactToFolder,
|
||||||
} from '@/api/hooks';
|
} from '@/api/hooks';
|
||||||
import { buildFolderTree, type ContactFolderTreeNode } from '@/api/contactFolders';
|
import { buildFolderTree, type ContactFolderTreeNode } from '@/api/contactFolders';
|
||||||
import { ChevronRight, Folder, MoreVertical, Palette, Pencil, Pin, Plus, Tag, Trash2, Users } from 'lucide-react';
|
import { ChevronRight, Folder, MoreVertical, Palette, Pencil, Pin, Plus, Tag, Trash2, Users } from 'lucide-react';
|
||||||
@@ -81,7 +82,6 @@ function FolderDropdown({
|
|||||||
{ label: 'L\u00f6schen', icon: Trash2, action: () => { onDelete(state.folderId); onClose(); }, danger: true },
|
{ label: 'L\u00f6schen', icon: Trash2, action: () => { onDelete(state.folderId); onClose(); }, danger: true },
|
||||||
];
|
];
|
||||||
|
|
||||||
// Position dropdown below the button, aligned right
|
|
||||||
const top = state.anchorRect.bottom + 4;
|
const top = state.anchorRect.bottom + 4;
|
||||||
const left = Math.max(4, state.anchorRect.right - 160);
|
const left = Math.max(4, state.anchorRect.right - 160);
|
||||||
|
|
||||||
@@ -116,12 +116,20 @@ function FolderTreeItem({
|
|||||||
selectedFilter,
|
selectedFilter,
|
||||||
onSelectFolder,
|
onSelectFolder,
|
||||||
onMoreClick,
|
onMoreClick,
|
||||||
|
isDragOver,
|
||||||
|
onDragOver,
|
||||||
|
onDragLeave,
|
||||||
|
onDrop,
|
||||||
}: {
|
}: {
|
||||||
node: ContactFolderTreeNode;
|
node: ContactFolderTreeNode;
|
||||||
depth: number;
|
depth: number;
|
||||||
selectedFilter: ContactFilter;
|
selectedFilter: ContactFilter;
|
||||||
onSelectFolder: (folderId: string) => void;
|
onSelectFolder: (folderId: string) => void;
|
||||||
onMoreClick: (e: React.MouseEvent, folderId: string) => void;
|
onMoreClick: (e: React.MouseEvent, folderId: string) => void;
|
||||||
|
isDragOver: boolean;
|
||||||
|
onDragOver: (e: React.DragEvent, folderId: string) => void;
|
||||||
|
onDragLeave: (folderId: string) => void;
|
||||||
|
onDrop: (e: React.DragEvent, folderId: string) => void;
|
||||||
}) {
|
}) {
|
||||||
const [expanded, setExpanded] = useState(true);
|
const [expanded, setExpanded] = useState(true);
|
||||||
const folderKey = `folder:${node.id}` as ContactFilter;
|
const folderKey = `folder:${node.id}` as ContactFilter;
|
||||||
@@ -130,10 +138,15 @@ function FolderTreeItem({
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div
|
<div
|
||||||
|
onDragOver={(e) => onDragOver(e, node.id)}
|
||||||
|
onDragLeave={() => onDragLeave(node.id)}
|
||||||
|
onDrop={(e) => onDrop(e, node.id)}
|
||||||
className={clsx(
|
className={clsx(
|
||||||
'group flex items-center gap-1.5 px-2 py-1.5 text-sm font-medium rounded-md cursor-pointer min-h-touch',
|
'group flex items-center gap-1.5 px-2 py-1.5 text-sm font-medium rounded-md cursor-pointer min-h-touch',
|
||||||
'transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500',
|
'transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500',
|
||||||
isActive
|
isDragOver
|
||||||
|
? 'bg-primary-100 ring-2 ring-primary-400'
|
||||||
|
: isActive
|
||||||
? 'bg-primary-50 text-primary-700'
|
? 'bg-primary-50 text-primary-700'
|
||||||
: 'text-secondary-700 hover:bg-secondary-100',
|
: 'text-secondary-700 hover:bg-secondary-100',
|
||||||
)}
|
)}
|
||||||
@@ -167,6 +180,10 @@ function FolderTreeItem({
|
|||||||
selectedFilter={selectedFilter}
|
selectedFilter={selectedFilter}
|
||||||
onSelectFolder={onSelectFolder}
|
onSelectFolder={onSelectFolder}
|
||||||
onMoreClick={onMoreClick}
|
onMoreClick={onMoreClick}
|
||||||
|
isDragOver={false}
|
||||||
|
onDragOver={onDragOver}
|
||||||
|
onDragLeave={onDragLeave}
|
||||||
|
onDrop={onDrop}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -185,11 +202,13 @@ export function ContactFolderTree({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [tagsOpen, setTagsOpen] = useState(true);
|
const [tagsOpen, setTagsOpen] = useState(true);
|
||||||
const [dropdown, setDropdown] = useState<DropdownState | null>(null);
|
const [dropdown, setDropdown] = useState<DropdownState | null>(null);
|
||||||
|
const [dragOverFolderId, setDragOverFolderId] = useState<string | null>(null);
|
||||||
|
|
||||||
const { data: folders, isLoading: foldersLoading } = useContactFolders();
|
const { data: folders, isLoading: foldersLoading } = useContactFolders();
|
||||||
const createFolderMut = useCreateContactFolder();
|
const createFolderMut = useCreateContactFolder();
|
||||||
const updateFolderMut = useUpdateContactFolder();
|
const updateFolderMut = useUpdateContactFolder();
|
||||||
const deleteFolderMut = useDeleteContactFolder();
|
const deleteFolderMut = useDeleteContactFolder();
|
||||||
|
const moveContactMut = useMoveContactToFolder();
|
||||||
|
|
||||||
const folderList = folders ?? [];
|
const folderList = folders ?? [];
|
||||||
const tree = buildFolderTree(folderList);
|
const tree = buildFolderTree(folderList);
|
||||||
@@ -238,6 +257,37 @@ export function ContactFolderTree({
|
|||||||
updateFolderMut.mutate({ id, data: { pinned: !pinned } as any });
|
updateFolderMut.mutate({ id, data: { pinned: !pinned } as any });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Drag and Drop handlers
|
||||||
|
const handleDragOver = (e: React.DragEvent, folderId: string) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
setDragOverFolderId(folderId);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDragLeave = (folderId: string) => {
|
||||||
|
if (dragOverFolderId === folderId) setDragOverFolderId(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDrop = (e: React.DragEvent, folderId: string) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
setDragOverFolderId(null);
|
||||||
|
const contactId = e.dataTransfer.getData('text/plain');
|
||||||
|
if (!contactId) return;
|
||||||
|
moveContactMut.mutate({ contactId, folderId });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRootDrop = (e: React.DragEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const contactId = e.dataTransfer.getData('text/plain');
|
||||||
|
if (!contactId) return;
|
||||||
|
moveContactMut.mutate({ contactId, folderId: null });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRootDragOver = (e: React.DragEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
};
|
||||||
|
|
||||||
const handleSelectFolder = useCallback((folderId: string) => {
|
const handleSelectFolder = useCallback((folderId: string) => {
|
||||||
onSelect(`folder:${folderId}` as ContactFilter);
|
onSelect(`folder:${folderId}` as ContactFilter);
|
||||||
}, [onSelect]);
|
}, [onSelect]);
|
||||||
@@ -267,8 +317,11 @@ export function ContactFolderTree({
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Folder tree */}
|
{/* Folder tree with drag-drop */}
|
||||||
<div>
|
<div
|
||||||
|
onDragOver={handleRootDragOver}
|
||||||
|
onDrop={handleRootDrop}
|
||||||
|
>
|
||||||
{tree.map((node) => (
|
{tree.map((node) => (
|
||||||
<FolderTreeItem
|
<FolderTreeItem
|
||||||
key={node.id}
|
key={node.id}
|
||||||
@@ -277,9 +330,20 @@ export function ContactFolderTree({
|
|||||||
selectedFilter={selectedFilter}
|
selectedFilter={selectedFilter}
|
||||||
onSelectFolder={handleSelectFolder}
|
onSelectFolder={handleSelectFolder}
|
||||||
onMoreClick={handleMoreClick}
|
onMoreClick={handleMoreClick}
|
||||||
|
isDragOver={dragOverFolderId === node.id}
|
||||||
|
onDragOver={handleDragOver}
|
||||||
|
onDragLeave={handleDragLeave}
|
||||||
|
onDrop={handleDrop}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
{/* Root drop zone */}
|
||||||
|
<div
|
||||||
|
onDragOver={handleRootDragOver}
|
||||||
|
onDrop={handleRootDrop}
|
||||||
|
className="min-h-[12px] mt-1 rounded-md transition-colors hover:bg-secondary-50"
|
||||||
|
/>
|
||||||
|
|
||||||
{(foldersLoading || loading) && (
|
{(foldersLoading || loading) && (
|
||||||
<div className="px-2 py-1 text-xs text-secondary-400">{t('common.loading')}</div>
|
<div className="px-2 py-1 text-xs text-secondary-400">{t('common.loading')}</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user