refactor: Relocate handleClear Logic: Move the chat and diagram clearing logic to ChatPanel (or a Server Action) and have ChatInput call the onClearChat prop. Introduce a clearDiagram method in DiagramContext.

This commit is contained in:
dayuan.jiang
2025-03-27 08:09:22 +00:00
parent 7e0790d60f
commit 6c8b5c48a2
3 changed files with 16 additions and 10 deletions

View File

@@ -13,6 +13,7 @@ interface DiagramContextType {
resolverRef: React.Ref<((value: string) => void) | null>;
drawioRef: React.Ref<DrawIoEmbedRef | null>;
handleDiagramExport: (data: any) => void;
clearDiagram: () => void;
}
const DiagramContext = createContext<DiagramContextType | undefined>(undefined);
@@ -59,6 +60,14 @@ export function DiagramProvider({ children }: { children: React.ReactNode }) {
}
};
const clearDiagram = () => {
const emptyDiagram = `<mxfile><diagram name="Page-1" id="page-1"><mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>`;
loadDiagram(emptyDiagram);
setChartXML(emptyDiagram);
setLatestSvg("");
setDiagramHistory([]);
};
return (
<DiagramContext.Provider
value={{
@@ -70,6 +79,7 @@ export function DiagramProvider({ children }: { children: React.ReactNode }) {
resolverRef,
drawioRef,
handleDiagramExport,
clearDiagram,
}}
>
{children}