Skip to content

Commit

Permalink
improvement: add download to File Explorer (#2843)
Browse files Browse the repository at this point in the history
Download a file from the file explorer
  • Loading branch information
mscolnick authored Nov 12, 2024
1 parent 28d3d74 commit ea5c526
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions frontend/src/components/editor/file-tree/file-explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
Trash2Icon,
UploadIcon,
ViewIcon,
DownloadIcon,
} from "lucide-react";
import type { FileInfo } from "@/core/network/types";
import {
Expand Down Expand Up @@ -64,6 +65,8 @@ import type { RequestingTree } from "./requesting-tree";
import type { FilePath } from "@/utils/paths";
import useEvent from "react-use-event-hook";
import { copyToClipboard } from "@/utils/copy";
import { sendFileDetails } from "@/core/network/requests";
import { downloadBlob } from "@/utils/download";

const RequestingTreeContext = React.createContext<RequestingTree | null>(null);

Expand Down Expand Up @@ -492,6 +495,21 @@ const Node = ({ node, style, dragHandle }: NodeRendererProps<FileInfo>) => {
</>
)}
<DropdownMenuSeparator />
{!node.data.isDirectory && (
<>
<DropdownMenuItem
onSelect={async () => {
const details = await sendFileDetails({ path: node.data.path });
const contents = details.contents || "";
downloadBlob(new Blob([contents]), node.data.name);
}}
>
<DownloadIcon {...iconProps} />
Download
</DropdownMenuItem>
<DropdownMenuSeparator />
</>
)}
<DropdownMenuItem onSelect={handleDeleteFile} variant="danger">
<Trash2Icon {...iconProps} />
Delete
Expand Down

0 comments on commit ea5c526

Please sign in to comment.