feat: show full folder path in move/drop toast

This commit is contained in:
Linus Rath
2026-04-22 00:14:49 +02:00
parent b7374570c8
commit 468851ff25
2 changed files with 27 additions and 7 deletions
+8 -7
View File
@@ -6,6 +6,7 @@ import { useEmailStore } from "@/stores/email-store";
import { useAuthStore } from "@/stores/auth-store"; import { useAuthStore } from "@/stores/auth-store";
import { useDragDropContext } from "@/contexts/drag-drop-context"; import { useDragDropContext } from "@/contexts/drag-drop-context";
import { toast } from "@/stores/toast-store"; import { toast } from "@/stores/toast-store";
import { getMailboxPath } from "@/lib/utils";
interface UseMailboxDropOptions { interface UseMailboxDropOptions {
mailbox: Mailbox; mailbox: Mailbox;
@@ -30,7 +31,7 @@ interface UseMailboxDropReturn {
export function useMailboxDrop({ mailbox, onDropComplete, onSuccess, onError }: UseMailboxDropOptions): UseMailboxDropReturn { export function useMailboxDrop({ mailbox, onDropComplete, onSuccess, onError }: UseMailboxDropOptions): UseMailboxDropReturn {
const [isOver, setIsOver] = useState(false); const [isOver, setIsOver] = useState(false);
const { client } = useAuthStore(); const { client } = useAuthStore();
const { moveEmailsToMailbox, selectedEmailIds, clearSelection, fetchEmails, selectedMailbox } = useEmailStore(); const { moveEmailsToMailbox, selectedEmailIds, clearSelection, fetchEmails, selectedMailbox, mailboxes } = useEmailStore();
const { isDragging, sourceMailboxId, draggedEmails, endDrag } = useDragDropContext(); const { isDragging, sourceMailboxId, draggedEmails, endDrag } = useDragDropContext();
// Determine if this is a valid drop target // Determine if this is a valid drop target
@@ -117,15 +118,15 @@ export function useMailboxDrop({ mailbox, onDropComplete, onSuccess, onError }:
// Refresh the current mailbox view // Refresh the current mailbox view
await fetchEmails(client, selectedMailbox); await fetchEmails(client, selectedMailbox);
// Call success callback if provided, otherwise use fallback const mailboxPath = getMailboxPath(mailbox, mailboxes);
if (onSuccess) { if (onSuccess) {
onSuccess(emailIds.length, mailbox.name); onSuccess(emailIds.length, mailboxPath);
} else { } else {
// Fallback for backward compatibility
if (emailIds.length === 1) { if (emailIds.length === 1) {
toast.success("Email moved", `Moved to ${mailbox.name}`); toast.success("Email moved", `Moved to ${mailboxPath}`);
} else { } else {
toast.success("Emails moved", `${emailIds.length} emails moved to ${mailbox.name}`); toast.success("Emails moved", `${emailIds.length} emails moved to ${mailboxPath}`);
} }
} }
@@ -143,7 +144,7 @@ export function useMailboxDrop({ mailbox, onDropComplete, onSuccess, onError }:
} finally { } finally {
endDrag(); endDrag();
} }
}, [client, mailbox, isValidTarget, moveEmailsToMailbox, selectedEmailIds, clearSelection, fetchEmails, selectedMailbox, endDrag, onDropComplete, onSuccess, onError]); }, [client, mailbox, mailboxes, isValidTarget, moveEmailsToMailbox, selectedEmailIds, clearSelection, fetchEmails, selectedMailbox, endDrag, onDropComplete, onSuccess, onError]);
const valid = isValidTarget(); const valid = isValidTarget();
+19
View File
@@ -430,3 +430,22 @@ export function flattenMailboxTree(nodes: MailboxNode[]): MailboxNode[] {
traverse(nodes); traverse(nodes);
return result; return result;
} }
export function getMailboxPath(
mailbox: Pick<Mailbox, 'id' | 'name' | 'parentId'>,
allMailboxes: Array<Pick<Mailbox, 'id' | 'name' | 'parentId'>>,
separator = ' ',
): string {
const byId = new Map(allMailboxes.map(m => [m.id, m]));
const names: string[] = [mailbox.name];
const visited = new Set<string>([mailbox.id]);
let parentId = mailbox.parentId;
while (parentId && !visited.has(parentId)) {
visited.add(parentId);
const parent = byId.get(parentId);
if (!parent) break;
names.unshift(parent.name);
parentId = parent.parentId;
}
return names.join(separator);
}