diff --git a/src/components/GenerateCourse/AICourseContent.tsx b/src/components/GenerateCourse/AICourseContent.tsx index 86930bde7..4f0d936ce 100644 --- a/src/components/GenerateCourse/AICourseContent.tsx +++ b/src/components/GenerateCourse/AICourseContent.tsx @@ -435,6 +435,9 @@ export function AICourseContent(props: AICourseContentProps) { void; +}; + +export function AICourseOutlineHeader(props: AICourseOutlineHeaderProps) { + const { course, isLoading, onRegenerateOutline } = props; + + return ( +
+
+

+ {course.title || 'Loading course ..'} +

+

+ {course.title ? course.difficulty : 'Please wait ..'} +

+
+ + {!isLoading && ( + + )} +
+ ); +} \ No newline at end of file diff --git a/src/components/GenerateCourse/AICourseOutlineView.tsx b/src/components/GenerateCourse/AICourseOutlineView.tsx index ed28f8830..7ab114ef3 100644 --- a/src/components/GenerateCourse/AICourseOutlineView.tsx +++ b/src/components/GenerateCourse/AICourseOutlineView.tsx @@ -1,4 +1,3 @@ -import { RegenerateOutline } from './RegenerateOutline'; import { cn } from '../../lib/classname'; import type { AiCourse } from '../../lib/ai'; import { slugify } from '../../lib/slugger'; @@ -6,6 +5,7 @@ import { CheckIcon } from '../ReactIcons/CheckIcon'; import type { Dispatch, SetStateAction } from 'react'; import { Loader2Icon } from 'lucide-react'; import type { AICourseViewMode } from './AICourseContent'; +import { AICourseOutlineHeader } from './AICourseOutlineHeader'; type AICourseOutlineViewProps = { course: AiCourse; @@ -33,26 +33,12 @@ export function AICourseOutlineView(props: AICourseOutlineViewProps) { const aiCourseProgress = course.done || []; return ( -
-
-
-

- {course.title || 'Loading course ..'} -

-

- {course.title ? course.difficulty : 'Please wait ..'} -

-
- - {!isLoading && ( - - )} -
+
+ {course.title ? (
{course.modules.map((courseModule, moduleIdx) => { diff --git a/src/components/GenerateCourse/AICourseRoadmapView.tsx b/src/components/GenerateCourse/AICourseRoadmapView.tsx index 987805e77..aa80bb0ab 100644 --- a/src/components/GenerateCourse/AICourseRoadmapView.tsx +++ b/src/components/GenerateCourse/AICourseRoadmapView.tsx @@ -22,10 +22,15 @@ import { renderTopicProgress } from '../../lib/resource-progress'; import { queryClient } from '../../stores/query-client'; import { useQuery } from '@tanstack/react-query'; import { billingDetailsOptions } from '../../queries/billing'; +import { AICourseOutlineHeader } from './AICourseOutlineHeader'; +import type { AiCourse } from '../../lib/ai'; export type AICourseRoadmapViewProps = { done: string[]; courseSlug: string; + course: AiCourse; + isLoading: boolean; + onRegenerateOutline: (prompt?: string) => void; setActiveModuleIndex: (index: number) => void; setActiveLessonIndex: (index: number) => void; setViewMode: (mode: AICourseViewMode) => void; @@ -37,6 +42,9 @@ export function AICourseRoadmapView(props: AICourseRoadmapViewProps) { const { done = [], courseSlug, + course, + isLoading, + onRegenerateOutline, setActiveModuleIndex, setActiveLessonIndex, setViewMode, @@ -47,7 +55,6 @@ export function AICourseRoadmapView(props: AICourseRoadmapViewProps) { const containerEl = useRef(null); const [roadmapStructure, setRoadmapStructure] = useState([]); - const [isLoading, setIsLoading] = useState(true); const [isGenerating, setIsGenerating] = useState(false); const [error, setError] = useState(null); @@ -76,7 +83,7 @@ export function AICourseRoadmapView(props: AICourseRoadmapViewProps) { data?.message || 'Something went wrong', ); setError(data?.message || 'Something went wrong'); - setIsLoading(false); + setIsGenerating(false); return; } @@ -84,11 +91,10 @@ export function AICourseRoadmapView(props: AICourseRoadmapViewProps) { if (!reader) { console.error('Failed to get reader from response'); setError('Something went wrong'); - setIsLoading(false); + setIsGenerating(false); return; } - setIsLoading(false); setIsGenerating(true); await readAIRoadmapStream(reader, { onStream: async (result) => { @@ -124,7 +130,7 @@ export function AICourseRoadmapView(props: AICourseRoadmapViewProps) { } catch (error) { console.error('Error generating course roadmap:', error); setError('Something went wrong'); - setIsLoading(false); + setIsGenerating(false); } }; @@ -138,7 +144,7 @@ export function AICourseRoadmapView(props: AICourseRoadmapViewProps) { const handleNodeClick = useCallback( (e: MouseEvent) => { - if (isLoading || isGenerating) { + if (isGenerating) { return; } @@ -189,7 +195,6 @@ export function AICourseRoadmapView(props: AICourseRoadmapViewProps) { setViewMode('module'); }, [ - isLoading, roadmapStructure, setExpandedModules, setActiveModuleIndex, @@ -200,13 +205,21 @@ export function AICourseRoadmapView(props: AICourseRoadmapViewProps) { return (
+ { + setViewMode('outline'); + onRegenerateOutline(prompt); + }} + /> {isLoading && (
)} - {error && !isLoading && !isGenerating && ( + {error && !isGenerating && (