Files
outline/app/components/DownloadToast.tsx
T
Tom MoorandClaude Opus 5 cc15b088ec feat: Show a toast with actions when a file download completes in the desktop app (#13769)
* Show toast with actions when a file download completes

In the desktop app a toast is now displayed when a file finishes
downloading, with the option to open the file or reveal it in the file
manager of the operating system.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kat47mueTm3CUZSbDVfBas

* Guard download bridge calls for older desktop apps

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kat47mueTm3CUZSbDVfBas

* Change protocol in dev for easier testing

* Use standard buttons stacked below the file name in download toast

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-09-17 19:36:47 -04:00

72 lines
1.9 KiB
TypeScript

import { t } from "i18next";
import { useCallback } from "react";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";
import Button from "~/components/Button";
import Flex from "~/components/Flex";
import Desktop from "~/utils/Desktop";
type DownloadedFile = {
/** The user facing name of the downloaded file. */
fileName: string;
/** The absolute path the file was saved to. */
filePath: string;
};
/**
* Displays a toast notifying that a file finished downloading, with the file
* name and actions to open the file or reveal it in the file manager. Desktop
* app only.
*
* @param file the name and path of the downloaded file.
*/
export function showDownloadToast(file: DownloadedFile) {
const toastId = `download-${file.filePath}`;
toast.message(t("Download complete"), {
id: toastId,
description: <DownloadToastDescription file={file} toastId={toastId} />,
});
}
function DownloadToastDescription({
file,
toastId,
}: {
file: DownloadedFile;
toastId: string;
}) {
const { t } = useTranslation();
const handleOpen = useCallback(() => {
toast.dismiss(toastId);
void Desktop.bridge?.openDownload?.(file.filePath);
}, [file.filePath, toastId]);
const handleShowInFolder = useCallback(() => {
toast.dismiss(toastId);
void Desktop.bridge?.showDownloadInFolder?.(file.filePath);
}, [file.filePath, toastId]);
// The name given to the file manager differs by operating system.
const showInFolderLabel = Desktop.isMacApp()
? t("Show in Finder")
: Desktop.isWindowsApp()
? t("Show in Explorer")
: t("Show in folder");
return (
<Flex column gap={8}>
{file.fileName}
<Flex gap={4}>
<Button onClick={handleOpen} neutral>
{t("Open")}
</Button>
<Button onClick={handleShowInFolder} neutral>
{showInFolderLabel}
</Button>
</Flex>
</Flex>
);
}