diff --git a/components/chat-input.tsx b/components/chat-input.tsx index 01ebbf5..c03b688 100644 --- a/components/chat-input.tsx +++ b/components/chat-input.tsx @@ -28,6 +28,7 @@ import { import Image from "next/image"; import { useDiagram } from "@/contexts/diagram-context"; +import { HistoryDialog } from "@/components/history-dialog"; interface ChatInputProps { input: string; @@ -262,64 +263,10 @@ export function ChatInput({ - {/* History Dialog */} - - - - Diagram History - - Here saved each diagram before AI - modification. -
- Click on a diagram to restore it -
-
- - {diagramHistory.length === 0 ? ( -
- No history available yet. Send messages to - create diagram history. -
- ) : ( -
- {diagramHistory.map((item, index) => ( -
{ - onDisplayChart(item.xml); - setShowHistory(false); - }} - > -
- {`Diagram -
-
- Version {index + 1} -
-
- ))} -
- )} - - - - -
-
+
{/* History Button */} diff --git a/components/chat-panel.tsx b/components/chat-panel.tsx index f707632..c817909 100644 --- a/components/chat-panel.tsx +++ b/components/chat-panel.tsx @@ -17,16 +17,16 @@ import { useDiagram } from "@/contexts/diagram-context"; export default function ChatPanel() { const { - chartXML, loadDiagram: onDisplayChart, handleExport: onExport, resolverRef, - diagramHistory, } = useDiagram(); const onFetchChart = () => { return new Promise((resolve) => { - resolverRef.current = resolve; // Store the resolver + if (resolverRef && "current" in resolverRef) { + resolverRef.current = resolve; // Store the resolver + } onExport(); // Trigger the export }); }; @@ -94,12 +94,7 @@ export default function ChatPanel() { const handleFileChange = (newFiles: FileList | undefined) => { setFiles(newFiles); }; - - // Function to handle history item selection - const handleSelectHistoryItem = (xml: string) => { - onDisplayChart(xml); - setShowHistory(false); - }; + // Helper function to handle file input change return ( diff --git a/components/history-dialog.tsx b/components/history-dialog.tsx new file mode 100644 index 0000000..a027598 --- /dev/null +++ b/components/history-dialog.tsx @@ -0,0 +1,82 @@ +"use client"; + +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { Button } from "@/components/ui/button"; +import Image from "next/image"; +import { useDiagram } from "@/contexts/diagram-context"; + +interface HistoryDialogProps { + showHistory: boolean; + setShowHistory: (show: boolean) => void; +} + +export function HistoryDialog({ + showHistory, + setShowHistory, +}: HistoryDialogProps) { + const { loadDiagram: onDisplayChart, diagramHistory } = useDiagram(); + + return ( + + + + Diagram History + + Here saved each diagram before AI modification. +
+ Click on a diagram to restore it +
+
+ + {diagramHistory.length === 0 ? ( +
+ No history available yet. Send messages to create + diagram history. +
+ ) : ( +
+ {diagramHistory.map((item, index) => ( +
{ + onDisplayChart(item.xml); + setShowHistory(false); + }} + > +
+ {`Diagram +
+
+ Version {index + 1} +
+
+ ))} +
+ )} + + + + +
+
+ ); +}