feat: add save diagram to local file button (#60)

- Add save button in chat input area with download icon
- Create SaveDialog component for filename input
- Export current diagram as .drawio file format
- Support custom filename with default timestamp-based name

Closes #53
This commit is contained in:
Dayuan Jiang
2025-12-03 21:02:26 +09:00
committed by GitHub
parent a61d37c818
commit 45f74df349
3 changed files with 143 additions and 1 deletions

View File

@@ -4,12 +4,14 @@ import React, { useCallback, useRef, useEffect, useState } from "react";
import { Button } from "@/components/ui/button";
import { Textarea } from "@/components/ui/textarea";
import { ResetWarningModal } from "@/components/reset-warning-modal";
import { SaveDialog } from "@/components/save-dialog";
import {
Loader2,
Send,
RotateCcw,
Image as ImageIcon,
History,
Download,
} from "lucide-react";
import { ButtonWithTooltip } from "@/components/button-with-tooltip";
import { FilePreviewList } from "./file-preview-list";
@@ -39,11 +41,12 @@ export function ChatInput({
showHistory = false,
onToggleHistory = () => {},
}: ChatInputProps) {
const { diagramHistory } = useDiagram();
const { diagramHistory, saveDiagramToFile } = useDiagram();
const textareaRef = useRef<HTMLTextAreaElement>(null);
const fileInputRef = useRef<HTMLInputElement>(null);
const [isDragging, setIsDragging] = useState(false);
const [showClearDialog, setShowClearDialog] = useState(false);
const [showSaveDialog, setShowSaveDialog] = useState(false);
// Debug: Log status changes
const isDisabled = status === "streaming" || status === "submitted";
@@ -166,6 +169,7 @@ export function ChatInput({
setShowClearDialog(false);
};
return (
<form
onSubmit={onSubmit}
@@ -235,6 +239,25 @@ export function ChatInput({
<History className="h-4 w-4" />
</ButtonWithTooltip>
{/* Save Diagram Button */}
<ButtonWithTooltip
type="button"
variant="outline"
size="icon"
onClick={() => setShowSaveDialog(true)}
disabled={isDisabled}
tooltipContent="Save diagram to local file"
>
<Download className="h-4 w-4" />
</ButtonWithTooltip>
<SaveDialog
open={showSaveDialog}
onOpenChange={setShowSaveDialog}
onSave={saveDiagramToFile}
defaultFilename={`diagram-${new Date().toISOString().slice(0, 10)}`}
/>
<Button
type="button"
variant="outline"