diff --git a/src/components/GenerateCourse/AICourseRoadmapView.tsx b/src/components/GenerateCourse/AICourseRoadmapView.tsx index 106a2b764..8300f1cfc 100644 --- a/src/components/GenerateCourse/AICourseRoadmapView.tsx +++ b/src/components/GenerateCourse/AICourseRoadmapView.tsx @@ -4,7 +4,6 @@ import { generateAIRoadmapFromText } from '../../../editor/utils/roadmap-generat import { generateAICourseRoadmapStructure, readAIRoadmapStream, - type AiCourse, type ResultItem, } from '../../lib/ai'; import { @@ -128,7 +127,31 @@ export function AICourseRoadmapView(props: AICourseRoadmapViewProps) { const nodeId = targetGroup?.dataset?.nodeId; const nodeType = targetGroup?.dataset?.type; - if (!nodeId || !nodeType || nodeType !== 'subtopic') { + if (!nodeId || !nodeType) { + return null; + } + + if (nodeType === 'topic') { + const topicIndex = roadmapStructure + .filter((item) => item.type === 'topic') + .findIndex((item) => item.id === nodeId); + + setExpandedModules((prev) => { + const newState: Record = {}; + roadmapStructure.forEach((_, idx) => { + newState[idx] = false; + }); + newState[topicIndex] = true; + return newState; + }); + + setActiveModuleIndex(topicIndex); + setActiveLessonIndex(0); + setViewMode('module'); + return; + } + + if (nodeType !== 'subtopic') { return null; } @@ -156,7 +179,7 @@ export function AICourseRoadmapView(props: AICourseRoadmapViewProps) { ); return ( -
+
{isLoading && (
diff --git a/src/lib/ai.ts b/src/lib/ai.ts index 9713fd162..d401da377 100644 --- a/src/lib/ai.ts +++ b/src/lib/ai.ts @@ -126,7 +126,7 @@ export async function readAIRoadmapStream( for (let i = 0; i < value.length; i++) { if (value[i] === NEW_LINE) { result += decoder.decode(value.slice(start, i + 1)); - onStream?.(result); + await onStream?.(result); start = i + 1; } } @@ -136,8 +136,8 @@ export async function readAIRoadmapStream( } } - onStream?.(result); - onStreamEnd?.(result); + await onStream?.(result); + await onStreamEnd?.(result); reader.releaseLock(); }