diff --git a/src/components/GenerateRoadmap/AITermSuggestionInput.tsx b/src/components/GenerateRoadmap/AITermSuggestionInput.tsx index d6c98e411..f8b57ffbc 100644 --- a/src/components/GenerateRoadmap/AITermSuggestionInput.tsx +++ b/src/components/GenerateRoadmap/AITermSuggestionInput.tsx @@ -10,6 +10,7 @@ import { useOutsideClick } from '../../hooks/use-outside-click'; import { useDebounceValue } from '../../hooks/use-debounce'; import { httpGet } from '../../lib/http'; import { useToast } from '../../hooks/use-toast'; +import { Loader2 } from 'lucide-react'; type GetTopAIRoadmapTermResponse = { _id: string; @@ -24,7 +25,10 @@ type AITermSuggestionInputProps = { inputClassName?: string; wrapperClassName?: string; placeholder?: string; -} & Omit, 'onSelect' | 'onChange'>; +} & Omit< + InputHTMLAttributes, + 'onSelect' | 'onChange' | 'className' +>; export function AITermSuggestionInput(props: AITermSuggestionInputProps) { const { @@ -47,6 +51,7 @@ export function AITermSuggestionInput(props: AITermSuggestionInputProps) { const dropdownRef = useRef(null); const [isActive, setIsActive] = useState(false); + const [isLoading, setIsLoading] = useState(false); const [searchResults, setSearchResults] = useState([]); const [searchedText, setSearchedText] = useState(defaultValue); @@ -87,9 +92,11 @@ export function AITermSuggestionInput(props: AITermSuggestionInputProps) { } setIsActive(true); + setIsLoading(true); loadTopAIRoadmapTerm().then((results) => { setSearchResults(results?.slice(0, 5) || []); setActiveCounter(0); + setIsLoading(false); }); }, [debouncedSearchValue]); @@ -103,9 +110,9 @@ export function AITermSuggestionInput(props: AITermSuggestionInputProps) { {...inputProps} ref={searchInputRef} type="text" - value={searchedText} + value={defaultValue} className={cn( - 'w-full rounded-md border border-gray-400 px-3 py-2.5 transition-colors focus:border-black focus:outline-none', + 'w-full rounded-md border border-gray-400 px-3 py-2.5 pr-8 transition-colors focus:border-black focus:outline-none', inputClassName, )} placeholder={placeholder} @@ -146,7 +153,13 @@ export function AITermSuggestionInput(props: AITermSuggestionInputProps) { }} /> - {isActive && searchResults.length > 0 && ( + {isLoading && ( +
+ +
+ )} + + {isActive && searchResults.length > 0 && searchedText.length > 0 && (
(`${import.meta.env.PUBLIC_API_URL}/v1-get-ai-roadmap/${roadmapId}`); @@ -516,15 +518,15 @@ export function GenerateRoadmap() { onSubmit={handleSubmit} className="my-3 flex w-full flex-col gap-2 sm:flex-row sm:items-center sm:justify-center" > - - setRoadmapTerm((e.target as HTMLInputElement).value) - } + onValueChange={(value) => setRoadmapTerm(value)} + placeholder="e.g. Try searching for Ansible or DevOps" + wrapperClassName="grow" + onSelect={(id) => { + setUrlParams({ id }); + }} />