Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions contexts/diagram-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ export function DiagramProvider({ children }: { children: React.ReactNode }) {
>([]);
const drawioRef = useRef<DrawIoEmbedRef | null>(null);
const resolverRef = useRef<((value: string) => void) | null>(null);
// Track if we're expecting an export for history (user-initiated)
const expectHistoryExportRef = useRef<boolean>(false);

const handleExport = () => {
if (drawioRef.current) {
// Mark that this export should be saved to history
expectHistoryExportRef.current = true;
drawioRef.current.exportDiagram({
format: "xmlsvg",
});
Expand All @@ -47,13 +51,19 @@ export function DiagramProvider({ children }: { children: React.ReactNode }) {
const extractedXML = extractDiagramXML(data.data);
setChartXML(extractedXML);
setLatestSvg(data.data);
setDiagramHistory((prev) => [
...prev,
{
svg: data.data,
xml: extractedXML,
},
]);

// Only add to history if this was a user-initiated export
if (expectHistoryExportRef.current) {
setDiagramHistory((prev) => [
...prev,
{
svg: data.data,
xml: extractedXML,
},
]);
expectHistoryExportRef.current = false;
}

if (resolverRef.current) {
resolverRef.current(extractedXML);
resolverRef.current = null;
Expand Down
Loading