From 204a421559762d1d1976e83749965e3c687caeff Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Wed, 9 Apr 2025 16:55:38 +0100 Subject: [PATCH] Add ai-course dropdown --- src/components/AITutor/AITutorLayout.tsx | 2 +- src/components/AITutor/DifficultyDropdown.tsx | 69 +++++++++++++++++++ src/components/GenerateCourse/AICourse.tsx | 65 +++++------------ .../GenerateCourse/FineTuneCourse.tsx | 2 +- 4 files changed, 88 insertions(+), 50 deletions(-) create mode 100644 src/components/AITutor/DifficultyDropdown.tsx diff --git a/src/components/AITutor/AITutorLayout.tsx b/src/components/AITutor/AITutorLayout.tsx index 5cfe7f3ce..c7663c48f 100644 --- a/src/components/AITutor/AITutorLayout.tsx +++ b/src/components/AITutor/AITutorLayout.tsx @@ -11,7 +11,7 @@ export function AITutorLayout(props: AITutorLayoutProps) { return (
-
+
{children}
diff --git a/src/components/AITutor/DifficultyDropdown.tsx b/src/components/AITutor/DifficultyDropdown.tsx new file mode 100644 index 000000000..0f5320090 --- /dev/null +++ b/src/components/AITutor/DifficultyDropdown.tsx @@ -0,0 +1,69 @@ +import { ChevronDown } from 'lucide-react'; +import { useState, useRef, useEffect } from 'react'; +import { cn } from '../../lib/classname'; +import { + difficultyLevels, + type DifficultyLevel, +} from '../GenerateCourse/AICourse'; + +type DifficultyDropdownProps = { + value: DifficultyLevel; + onChange: (value: DifficultyLevel) => void; +}; + +export function DifficultyDropdown(props: DifficultyDropdownProps) { + const { value, onChange } = props; + + const [isOpen, setIsOpen] = useState(false); + const dropdownRef = useRef(null); + + useEffect(() => { + function handleClickOutside(event: MouseEvent) { + if ( + dropdownRef.current && + !dropdownRef.current.contains(event.target as Node) + ) { + setIsOpen(false); + } + } + + document.addEventListener('mousedown', handleClickOutside); + return () => document.removeEventListener('mousedown', handleClickOutside); + }, []); + + return ( +
+ + + {isOpen && ( +
+ {difficultyLevels.map((level) => ( + + ))} +
+ )} +
+ ); +} diff --git a/src/components/GenerateCourse/AICourse.tsx b/src/components/GenerateCourse/AICourse.tsx index 428fb21fe..6fa957a42 100644 --- a/src/components/GenerateCourse/AICourse.tsx +++ b/src/components/GenerateCourse/AICourse.tsx @@ -1,9 +1,10 @@ -import { SearchIcon, WandIcon } from 'lucide-react'; +import { WandIcon } from 'lucide-react'; import { useEffect, useState } from 'react'; import { cn } from '../../lib/classname'; import { isLoggedIn } from '../../lib/jwt'; import { showLoginPopup } from '../../lib/popup'; import { FineTuneCourse } from './FineTuneCourse'; +import { DifficultyDropdown } from '../AITutor/DifficultyDropdown'; import { clearFineTuneData, getCourseFineTuneData, @@ -71,7 +72,7 @@ export function AICourse(props: AICourseProps) { } return ( -
+

What can I help you learn?

@@ -79,59 +80,27 @@ export function AICourse(props: AICourseProps) { Enter a topic below to generate a personalized course for it

-
+
{ e.preventDefault(); onSubmit(); }} > -
- -
-
- -
- setKeyword(e.target.value)} - onKeyDown={handleKeyDown} - placeholder="e.g., Algebra, JavaScript, Photography" - className="w-full rounded-md border border-gray-300 bg-white p-3 pl-10 text-gray-900 focus:ring-1 focus:ring-gray-500 focus:outline-hidden max-sm:placeholder:text-base" - maxLength={50} - /> -
-
+ setKeyword(e.target.value)} + onKeyDown={handleKeyDown} + placeholder="Ask tutor to teach you..." + className="w-full rounded-md border-none bg-transparent px-4 pt-4 pb-8 text-gray-900 focus:outline-hidden max-sm:placeholder:text-base" + maxLength={50} + /> -
- -
- {difficultyLevels.map((level) => ( - - ))} -
+
+
+