- {isLoading && !svg && (
+ {isLoading && (
diff --git a/src/components/AIRoadmap/GenerateAIRoadmap.tsx b/src/components/AIRoadmap/GenerateAIRoadmap.tsx
index f0ede7557..fe6eb2957 100644
--- a/src/components/AIRoadmap/GenerateAIRoadmap.tsx
+++ b/src/components/AIRoadmap/GenerateAIRoadmap.tsx
@@ -6,7 +6,7 @@ import { LoadingChip } from '../LoadingChip';
import type { QuestionAnswerChatMessage } from '../ContentGenerator/QuestionAnswerChat';
import { getQuestionAnswerChatMessages } from '../../lib/ai-questions';
import { aiRoadmapOptions, generateAIRoadmap } from '../../queries/ai-roadmap';
-import { replaceChildren } from '../../lib/dom';
+import { AIRoadmapContent } from './AIRoadmapContent';
type GenerateAIRoadmapProps = {
onRoadmapSlugChange?: (roadmapSlug: string) => void;
@@ -19,9 +19,9 @@ export function GenerateAIRoadmap(props: GenerateAIRoadmapProps) {
const [isStreaming, setIsStreaming] = useState(false);
const [error, setError] = useState('');
+ const [svgHtml, setSvgHtml] = useState('');
const [content, setContent] = useState('');
- const svgRef = useRef
(null);
- const containerRef = useRef(null);
+ const svgRef = useRef(null);
useEffect(() => {
const params = getUrlParams();
@@ -74,7 +74,7 @@ export function GenerateAIRoadmap(props: GenerateAIRoadmapProps) {
data: content,
questionAndAnswers,
viewCount: 0,
- svg: svgRef.current,
+ svgHtml: svgRef.current || '',
lastVisitedAt: new Date(),
createdAt: new Date(),
updatedAt: new Date(),
@@ -92,10 +92,9 @@ export function GenerateAIRoadmap(props: GenerateAIRoadmapProps) {
onError: setError,
onStreamingChange: setIsStreaming,
onRoadmapSvgChange: (svg) => {
- svgRef.current = svg;
- if (containerRef.current) {
- replaceChildren(containerRef.current, svg);
- }
+ const svgHtml = svg.outerHTML;
+ svgRef.current = svgHtml;
+ setSvgHtml(svgHtml);
},
});
};
@@ -112,11 +111,5 @@ export function GenerateAIRoadmap(props: GenerateAIRoadmapProps) {
);
}
- return (
-
- );
+ return ;
}
diff --git a/src/queries/ai-roadmap.ts b/src/queries/ai-roadmap.ts
index 4b943465b..7ecac3f6b 100644
--- a/src/queries/ai-roadmap.ts
+++ b/src/queries/ai-roadmap.ts
@@ -19,13 +19,10 @@ export interface AIRoadmapDocument {
}
export type AIRoadmapResponse = AIRoadmapDocument & {
- svg?: SVGElement | null;
+ svgHtml?: string;
};
-export function aiRoadmapOptions(
- roadmapSlug?: string,
- containerRef?: RefObject,
-) {
+export function aiRoadmapOptions(roadmapSlug?: string) {
return queryOptions({
queryKey: ['ai-roadmap', roadmapSlug],
queryFn: async () => {
@@ -36,13 +33,11 @@ export function aiRoadmapOptions(
const result = generateAICourseRoadmapStructure(res.data);
const { nodes, edges } = generateAIRoadmapFromText(result);
const svg = await renderFlowJSON({ nodes, edges });
- if (containerRef?.current) {
- replaceChildren(containerRef.current, svg);
- }
+ const svgHtml = svg.outerHTML;
return {
...res,
- svg,
+ svgHtml,
};
},
enabled: !!roadmapSlug,
@@ -52,10 +47,7 @@ export function aiRoadmapOptions(
import { queryClient } from '../stores/query-client';
import { getAiCourseLimitOptions } from '../queries/ai-course';
import { readChatStream } from '../lib/chat';
-import { markdownToHtmlWithHighlighting } from '../lib/markdown';
import type { QuestionAnswerChatMessage } from '../components/ContentGenerator/QuestionAnswerChat';
-import type { RefObject } from 'react';
-import { replaceChildren } from '../lib/dom';
type RoadmapDetails = {
roadmapId: string;