Bläddra i källkod

remove input text cooldown

Matthew Trejo 1 månad sedan
förälder
incheckning
2a63535a68
2 ändrade filer med 17 tillägg och 18 borttagningar
  1. 11 0
      src/components/chatbot/ChatInput.tsx
  2. 6 18
      src/hooks/useChat.ts

+ 11 - 0
src/components/chatbot/ChatInput.tsx

@@ -1,6 +1,7 @@
 import { Button } from "@/components/ui/button";
 import { Input } from "@/components/ui/input";
 import { Send, StopCircle } from "lucide-react";
+import { useEffect, useRef } from "react";
 
 interface ChatInputProps {
   inputMessage: string;
@@ -23,6 +24,15 @@ export const ChatInput = ({
   onEndConversation,
   hasMessages = false,
 }: ChatInputProps) => {
+  const inputRef = useRef<HTMLInputElement>(null);
+
+  // Autofocus cuando el input se habilita después de isLoading
+  useEffect(() => {
+    if (!isLoading && !isLimitReached && inputRef.current) {
+      inputRef.current.focus();
+    }
+  }, [isLoading, isLimitReached]);
+
   const handleKeyPress = (e: React.KeyboardEvent) => {
     if (e.key === "Enter" && !e.shiftKey) {
       e.preventDefault();
@@ -40,6 +50,7 @@ export const ChatInput = ({
       <div className="flex flex-col space-y-3">
         <div className="flex space-x-3">
           <Input
+            ref={inputRef}
             value={inputMessage}
             onChange={(e) => setInputMessage(e.target.value)}
             onKeyPress={handleKeyPress}

+ 6 - 18
src/hooks/useChat.ts

@@ -340,12 +340,8 @@ export const useChat = ({ chatType }: UseChatProps) => {
         if (!isPsychological && messageCount + 1 < MAX_MESSAGES && metadata.suggestions) {
           setCurrentSuggestions(metadata.suggestions);
           setShowDynamicSuggestions(true);
-          setInputDisabledForSuggestions(true);
-          
-          // Habilitar el input después de 3 segundos para dar tiempo a leer las sugerencias
-          setTimeout(() => {
-            setInputDisabledForSuggestions(false);
-          }, 3000);
+          // Input siempre habilitado - sin cooldown
+          setInputDisabledForSuggestions(false);
         }
       } else {
         console.log("❌ [CHAT] Error en respuesta de API - Status:", response.status);
@@ -383,12 +379,8 @@ export const useChat = ({ chatType }: UseChatProps) => {
         if (!isPsychological && messageCount + 1 < MAX_MESSAGES) {
           setCurrentSuggestions(fallbackMessage.suggestions || []);
           setShowDynamicSuggestions(true);
-          setInputDisabledForSuggestions(true);
-          
-          // Habilitar el input después de 3 segundos
-          setTimeout(() => {
-            setInputDisabledForSuggestions(false);
-          }, 3000);
+          // Input siempre habilitado - sin cooldown
+          setInputDisabledForSuggestions(false);
         }
       }
     } catch (error) {
@@ -467,12 +459,8 @@ export const useChat = ({ chatType }: UseChatProps) => {
       if (!isPsychological && messageCount + 1 < MAX_MESSAGES) {
         setCurrentSuggestions(fallbackMessage.suggestions || []);
         setShowDynamicSuggestions(true);
-        setInputDisabledForSuggestions(true);
-        
-        // Habilitar el input después de 3 segundos
-        setTimeout(() => {
-          setInputDisabledForSuggestions(false);
-        }, 3000);
+        // Input siempre habilitado - sin cooldown
+        setInputDisabledForSuggestions(false);
       }
     } finally {
       const totalTime = Date.now() - startTime;