"use client" import Image from "next/image" import { useState } from "react" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { useDiagram } from "@/contexts/diagram-context" interface HistoryDialogProps { showHistory: boolean onToggleHistory: (show: boolean) => void } export function HistoryDialog({ showHistory, onToggleHistory, }: HistoryDialogProps) { const { loadDiagram: onDisplayChart, diagramHistory } = useDiagram() const [selectedIndex, setSelectedIndex] = useState(null) const handleClose = () => { setSelectedIndex(null) onToggleHistory(false) } const handleConfirmRestore = () => { if (selectedIndex !== null) { onDisplayChart(diagramHistory[selectedIndex].xml) handleClose() } } 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) => (
setSelectedIndex(index)} >
{`Diagram
Version {index + 1}
))}
)} {selectedIndex !== null ? ( <>
Restore to Version {selectedIndex + 1}?
) : ( )}
) }