From 22edfecddf7e1ce51bedfc66bfa622b612ea3784 Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Wed, 4 Nov 2026 15:05:01 +0100 Subject: [PATCH] fix: go to the contacts or calendar import from a file's preview instead of staying in Files --- components/files/files-app.tsx | 4 ++-- lib/file-handoff-after-close.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 lib/file-handoff-after-close.ts diff --git a/components/files/files-app.tsx b/components/files/files-app.tsx index 048071738..0710ca8b2 100644 --- a/components/files/files-app.tsx +++ b/components/files/files-app.tsx @@ -40,7 +40,7 @@ import { formatRecipient } from "@/lib/email-composer-utils"; import { useRouter } from "@/i18n/navigation"; import { useEditAttachment } from "@/hooks/use-edit-attachment"; import { fileAppAction, type FileAppAction } from "@/lib/files-app-actions"; -import { handOffFiles } from "@/lib/launch-handoff"; +import { handOffFilesAfterClose } from "@/lib/file-handoff-after-close"; import { ImportEmlDialog } from "@/components/files/import-eml-dialog"; import { useCalendarStore } from "@/stores/calendar-store"; import { resolveConflictsInTurn, type ConflictAnswer, type UploadConflictResolver } from "@/lib/files-upload-conflicts"; @@ -740,7 +740,7 @@ export function FilesApp({ linkSegments: routeSegments }: FilesAppProps = {}) { } setPreviewFile(null); setInfoFile(null); - handOffFiles([file], action === "add-calendar" ? "calendar" : "contacts"); + void handOffFilesAfterClose([file], action === "add-calendar" ? "calendar" : "contacts"); }, [appActionOf, getFileContent, t]); const appActionFor = useCallback((r: FileResource) => { const action = appActionOf(r); diff --git a/lib/file-handoff-after-close.ts b/lib/file-handoff-after-close.ts new file mode 100644 index 000000000..693385470 --- /dev/null +++ b/lib/file-handoff-after-close.ts @@ -0,0 +1,15 @@ +import { historySettled } from '@/hooks/use-close-on-back'; +import { handOffFiles, type HandoffKind } from '@/lib/launch-handoff'; + +/** + * Hands files to another app (contacts or calendar import) from a layer that is + * closing, such as the Files preview. Closing it takes its history entry back + * with a Back that lands later; the handoff's move to /contacts or /calendar, + * started before that, was undone by it and left the user in Files (pim-p2-7). + * So: let the close commit, wait for that Back, then hand off. + */ +export async function handOffFilesAfterClose(files: File[], kind: HandoffKind): Promise { + await new Promise((resolve) => setTimeout(resolve, 0)); + await historySettled(); + handOffFiles(files, kind); +}