From 6819a929216851c54da8ce5de554c987a8f4205b Mon Sep 17 00:00:00 2001 From: "dayuan.jiang" Date: Sun, 23 Mar 2025 13:54:21 +0000 Subject: [PATCH] feat: implement diagram history functionality with history dialog in ChatInput and ChatPanel --- app/page.tsx | 20 ++++++++ components/chat-input.tsx | 96 ++++++++++++++++++++++++++++++++++++++- components/chatPanel.tsx | 19 ++++++++ 3 files changed, 134 insertions(+), 1 deletion(-) diff --git a/app/page.tsx b/app/page.tsx index c422de0..fbfa4d0 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -11,6 +11,12 @@ export default function Home() { const [chartXML, setChartXML] = useState(""); // Add a ref to store the resolver function const resolverRef = useRef<((value: string) => void) | null>(null); + // Add state for diagram history + const [diagramHistory, setDiagramHistory] = useState< + { svg: string; xml: string }[] + >([]); + // Add state for latest SVG + const [latestSvg, setLatestSvg] = useState(""); const handleExport = () => { if (drawioRef.current) { @@ -28,6 +34,16 @@ export default function Home() { } }; + // Add function to add current diagram to history + const addToHistory = () => { + if (latestSvg && chartXML) { + setDiagramHistory((prev) => [ + ...prev, + { svg: latestSvg, xml: chartXML }, + ]); + } + }; + return (
@@ -36,6 +52,8 @@ export default function Home() { onExport={(data) => { const extractedXML = extractDiagramXML(data.data); setChartXML(extractedXML); + // Store the latest SVG data + setLatestSvg(data.data); // If there's a pending resolver, resolve it with the fresh XML if (resolverRef.current) { resolverRef.current(extractedXML); @@ -61,6 +79,8 @@ export default function Home() { handleExport(); }); }} + diagramHistory={diagramHistory} + onAddToHistory={addToHistory} />
diff --git a/components/chat-input.tsx b/components/chat-input.tsx index 4a51c8b..facd5ce 100644 --- a/components/chat-input.tsx +++ b/components/chat-input.tsx @@ -3,7 +3,14 @@ import React, { useCallback, useRef, useEffect, useState } from "react"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; -import { Loader2, Send, RotateCcw, Image as ImageIcon, X } from "lucide-react"; +import { + Loader2, + Send, + RotateCcw, + Image as ImageIcon, + X, + History, +} from "lucide-react"; import { Tooltip, TooltipContent, @@ -30,6 +37,10 @@ interface ChatInputProps { onDisplayChart: (xml: string) => void; files?: FileList; onFileChange?: (files: FileList | undefined) => void; + diagramHistory?: { svg: string; xml: string }[]; + onSelectHistoryItem?: (xml: string) => void; + showHistory?: boolean; + setShowHistory?: (show: boolean) => void; } export function ChatInput({ @@ -41,6 +52,10 @@ export function ChatInput({ onDisplayChart, files, onFileChange, + diagramHistory = [], + onSelectHistoryItem = () => {}, + showHistory = false, + setShowHistory = () => {}, }: ChatInputProps) { const textareaRef = useRef(null); const fileInputRef = useRef(null); @@ -250,8 +265,87 @@ export function ChatInput({ + + {/* History Dialog */} + + + + Diagram History + + Click on a diagram to restore it + + + + {diagramHistory.length === 0 ? ( +
+ No history available yet. Send messages to + create diagram history. +
+ ) : ( +
+ {diagramHistory.map((item, index) => ( +
+ onSelectHistoryItem(item.xml) + } + > +
+ {`Diagram +
+
+ Version {index + 1} +
+
+ ))} +
+ )} + + + + +
+
+ {/* History Button */} + + + + + + + View diagram history + + + +