From 496a77ebbe54104e2c7cc9f8ecaad4d08e99e7a0 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Sat, 29 Mar 2025 01:40:56 +0600 Subject: [PATCH] fix: fixed position --- .../GenerateCourse/AICourseContent.tsx | 30 +- .../GenerateCourse/AICourseLesson.tsx | 62 ++-- .../GenerateCourse/AICourseLessonChat.tsx | 278 ++++++++++-------- 3 files changed, 191 insertions(+), 179 deletions(-) diff --git a/src/components/GenerateCourse/AICourseContent.tsx b/src/components/GenerateCourse/AICourseContent.tsx index c080c959b..37c197cc1 100644 --- a/src/components/GenerateCourse/AICourseContent.tsx +++ b/src/components/GenerateCourse/AICourseContent.tsx @@ -39,7 +39,7 @@ export function AICourseContent(props: AICourseContentProps) { const [showUpgradeModal, setShowUpgradeModal] = useState(false); const [showAILimitsPopup, setShowAILimitsPopup] = useState(false); - const [isAIChatsOpen, setIsAIChatsOpen] = useState(false); + const [isAIChatsOpen, setIsAIChatsOpen] = useState(true); const [activeModuleIndex, setActiveModuleIndex] = useState(0); const [activeLessonIndex, setActiveLessonIndex] = useState(0); @@ -144,6 +144,12 @@ export function AICourseContent(props: AICourseContentProps) { ); + useEffect(() => { + if (window && window?.innerWidth < 1024 && isAIChatsOpen) { + setIsAIChatsOpen(false); + } + }, []); + if (error && !isLoading) { const isLimitReached = error.includes('limit'); const isNotFound = error.includes('not exist'); @@ -239,18 +245,16 @@ export function AICourseContent(props: AICourseContentProps) { /> - {viewMode === 'module' && ( - - )} + - + )} diff --git a/src/components/GenerateCourse/AICourseLessonChat.tsx b/src/components/GenerateCourse/AICourseLessonChat.tsx index 7553800de..25717b259 100644 --- a/src/components/GenerateCourse/AICourseLessonChat.tsx +++ b/src/components/GenerateCourse/AICourseLessonChat.tsx @@ -6,6 +6,7 @@ import { HelpCircle, LockIcon, Send, + XIcon, } from 'lucide-react'; import { Fragment, @@ -29,6 +30,7 @@ import { import { getAiCourseLimitOptions } from '../../queries/ai-course'; import { queryClient } from '../../stores/query-client'; import { billingDetailsOptions } from '../../queries/billing'; +import { ResizablePanel } from './Resizeable'; export type AllowedAIChatRole = 'user' | 'assistant'; export type AIChatHistoryType = { @@ -46,6 +48,14 @@ type AICourseLessonChatProps = { isDisabled?: boolean; defaultQuestions?: string[]; + + courseAIChatHistory: AIChatHistoryType[]; + setCourseAIChatHistory: (history: AIChatHistoryType[]) => void; + + onClose: () => void; + + isAIChatsOpen: boolean; + setIsAIChatsOpen: (isOpen: boolean) => void; }; export function AICourseLessonChat(props: AICourseLessonChatProps) { @@ -56,23 +66,20 @@ export function AICourseLessonChat(props: AICourseLessonChatProps) { onUpgradeClick, isDisabled, defaultQuestions = [], + + courseAIChatHistory, + setCourseAIChatHistory, + + onClose, + + isAIChatsOpen, + setIsAIChatsOpen, } = props; const toast = useToast(); const scrollareaRef = useRef(null); const textareaRef = useRef(null); - const [courseAIChatHistory, setCourseAIChatHistory] = useState< - AIChatHistoryType[] - >([ - { - role: 'assistant', - content: - 'Hey, I am your AI instructor. Here are some examples of what you can ask me about 🤖', - isDefault: true, - }, - ]); - const [isStreamingMessage, setIsStreamingMessage] = useState(false); const [message, setMessage] = useState(''); const [streamedMessage, setStreamedMessage] = useState(''); @@ -203,132 +210,147 @@ export function AICourseLessonChat(props: AICourseLessonChatProps) { }, []); return ( - <> -
-
-
-

Course AI

-
+ +
+ -
-
-
-
- {courseAIChatHistory.map((chat, index) => { - return ( - - - - {chat.isDefault && !defaultQuestions?.length && ( -
-
- {capabilities.map((capability, index) => ( - - ))} -
+
+

Course AI

+
+ +
+
+
+
+ {courseAIChatHistory.map((chat, index) => { + return ( + + + + {chat.isDefault && !defaultQuestions?.length && ( +
+
+ {capabilities.map((capability, index) => ( + + ))}
- )} - - {chat.isDefault && defaultQuestions?.length > 1 && ( -
-
- {defaultQuestions.map((question, index) => ( - - ))} -
+
+ )} + + {chat.isDefault && defaultQuestions?.length > 1 && ( +
+
+ {defaultQuestions.map((question, index) => ( + + ))}
- )} - - ); - })} - - {isStreamingMessage && !streamedMessage && ( - - )} - - {streamedMessage && ( - - )} -
+
+ )} +
+ ); + })} + + {isStreamingMessage && !streamedMessage && ( + + )} + + {streamedMessage && ( + + )}
+
-
- {isLimitExceeded && ( -
- -

- Limit reached for today - {isPaidUser ? '. Please wait until tomorrow.' : ''} -

- {!isPaidUser && ( - - )} -
- )} - + {isLimitExceeded && ( +
+ +

+ Limit reached for today + {isPaidUser ? '. Please wait until tomorrow.' : ''} +

+ {!isPaidUser && ( + )} - placeholder="Ask AI anything about the lesson..." - value={message} - onChange={(e) => setMessage(e.target.value)} - autoFocus={true} - onKeyDown={(e) => { - if (e.key === 'Enter' && !e.shiftKey) { - handleChatSubmit(e as unknown as FormEvent); - } - }} - ref={textareaRef} - /> - - -
+
+ )} + setMessage(e.target.value)} + autoFocus={true} + onKeyDown={(e) => { + if (e.key === 'Enter' && !e.shiftKey) { + handleChatSubmit(e as unknown as FormEvent); + } + }} + ref={textareaRef} + /> + +
- + ); }