From 587dd66739ba5f783ff968c912e7acc7dcbc8f0b Mon Sep 17 00:00:00 2001
From: Arik Chakma <arikchangma@gmail.com>
Date: Fri, 28 Feb 2025 18:21:10 +0600
Subject: [PATCH] wip

---
 src/components/GenerateCourse/AICourse.tsx        | 12 ++++++++----
 src/components/GenerateCourse/AICourseContent.tsx |  5 +++++
 2 files changed, 13 insertions(+), 4 deletions(-)

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<DifficultyLevel>('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({});