diff --git a/src/components/GenerateCourse/AICourse.tsx b/src/components/GenerateCourse/AICourse.tsx index 2fb08a2a2..90ba82318 100644 --- a/src/components/GenerateCourse/AICourse.tsx +++ b/src/components/GenerateCourse/AICourse.tsx @@ -1,6 +1,8 @@ import { Loader2Icon, SearchIcon, WandIcon } from 'lucide-react'; import { useState } from 'react'; import { cn } from '../../lib/classname'; +import { isLoggedIn } from '../../lib/jwt'; +import { showLoginPopup } from '../../lib/popup'; export const difficultyLevels = [ 'beginner', @@ -14,18 +16,20 @@ type AICourseProps = {}; export function AICourse(props: AICourseProps) { const [keyword, setKeyword] = useState(''); const [difficulty, setDifficulty] = useState('intermediate'); - const [isLoading, setIsLoading] = useState(false); const handleKeyDown = (e: React.KeyboardEvent) => { - if (e.key === 'Enter' && keyword.trim() && !isLoading) { + if (e.key === 'Enter' && keyword.trim()) { onSubmit(); } }; function onSubmit() { - if (typeof window !== 'undefined') { - window.location.href = `/ai-tutor/search?term=${encodeURIComponent(keyword)}&difficulty=${difficulty}`; + if (!isLoggedIn()) { + showLoginPopup(); + return; } + + window.location.href = `/ai-tutor/search?term=${encodeURIComponent(keyword)}&difficulty=${difficulty}`; } return ( diff --git a/src/components/GenerateCourse/AICourseContent.tsx b/src/components/GenerateCourse/AICourseContent.tsx index 73e692d72..9b9ab8fef 100644 --- a/src/components/GenerateCourse/AICourseContent.tsx +++ b/src/components/GenerateCourse/AICourseContent.tsx @@ -12,6 +12,7 @@ import { readAICourseStream } from '../../helper/read-stream'; import { cn } from '../../lib/classname'; import { getUrlParams } from '../../lib/browser'; import { AICourseModuleView } from './AICourseModuleView'; +import { isLoggedIn } from '../../lib/jwt'; type Lesson = string; @@ -125,6 +126,10 @@ export function AICourseContent(props: AICourseContentProps) { difficulty?: string; slug?: string; }) => { + if (!isLoggedIn()) { + return; + } + setIsLoading(true); setStreamedCourse({ title: '', modules: [] }); setExpandedModules({});