Update outline generation

feat/ai-roadmap
Kamran Ahmed 3 weeks ago
parent fe4125dcb4
commit 32d9efc890
  1. 29
      src/components/GenerateCourse/AICourseRoadmapView.tsx
  2. 6
      src/lib/ai.ts

@ -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<number, boolean> = {};
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 (
<div className="relative mx-auto min-h-[200px] rounded-xl border border-gray-200 bg-white shadow-sm lg:max-w-3xl">
<div className="relative mx-auto min-h-[200px] rounded-xl border border-gray-200 bg-white shadow-sm lg:max-w-7xl">
{isLoading && (
<div className="absolute inset-0 flex h-full w-full items-center justify-center">
<Loader2Icon className="h-10 w-10 animate-spin stroke-[3px]" />

@ -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();
}

Loading…
Cancel
Save