|
|
@@ -1,6 +1,6 @@
|
|
|
"use client";
|
|
|
|
|
|
-import { useState, useEffect } from "react";
|
|
|
+import { useState, useEffect, useRef } from "react";
|
|
|
import { useSession } from "next-auth/react";
|
|
|
import { useChat, MAX_MESSAGES } from "@/hooks/useChat";
|
|
|
import { useChatEffects } from "@/hooks/useChatEffects";
|
|
|
@@ -25,6 +25,7 @@ interface ChatInterfaceProps {
|
|
|
|
|
|
export const ChatInterface = ({ chatType }: ChatInterfaceProps) => {
|
|
|
const { data: session } = useSession();
|
|
|
+ const chatContainerRef = useRef<HTMLDivElement>(null);
|
|
|
const [showReportModal, setShowReportModal] = useState(false);
|
|
|
const [showResetModal, setShowResetModal] = useState(false);
|
|
|
const [showLastMessageToast, setShowLastMessageToast] = useState(false);
|
|
|
@@ -158,9 +159,9 @@ export const ChatInterface = ({ chatType }: ChatInterfaceProps) => {
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
- <div className="min-h-screen flex items-center justify-center p-6">
|
|
|
- <div className="w-full max-w-6xl mx-auto">
|
|
|
- <div className="bg-card rounded-xl shadow-lg border border-border">
|
|
|
+ <div className="h-screen flex items-center justify-center p-6 overflow-hidden">
|
|
|
+ <div className="w-full max-w-6xl mx-auto h-full flex items-center">
|
|
|
+ <div className="bg-card rounded-xl shadow-lg border border-border w-full h-[90vh] flex flex-col">
|
|
|
{/* Header */}
|
|
|
<ChatHeader
|
|
|
remainingMessages={remainingMessages}
|
|
|
@@ -193,68 +194,66 @@ export const ChatInterface = ({ chatType }: ChatInterfaceProps) => {
|
|
|
/>
|
|
|
)}
|
|
|
|
|
|
- <div className="flex flex-col min-h-[70vh]">
|
|
|
- {/* Chat Content */}
|
|
|
- <div className="flex-1 overflow-hidden">
|
|
|
- <div className="h-full overflow-y-auto p-6 space-y-6">
|
|
|
- {/* Completed Banner */}
|
|
|
- {showCompletedBanner && (
|
|
|
- <CompletedBanner
|
|
|
- isGeneratingReport={isGeneratingReport}
|
|
|
- onDismiss={dismissCompletedBanner}
|
|
|
- />
|
|
|
- )}
|
|
|
-
|
|
|
- {/* Welcome Message */}
|
|
|
- {messages.length === 0 && (
|
|
|
- <WelcomeMessage maxMessages={MAX_MESSAGES} chatType={chatType} />
|
|
|
- )}
|
|
|
-
|
|
|
- {/* Suggested Prompts - solo para chat médico */}
|
|
|
- {chatType === "medical" && showSuggestions && messages.length === 0 && (
|
|
|
- <SuggestedPrompts
|
|
|
- onSuggestionClick={handleSuggestionClick}
|
|
|
- isLoading={isLoading}
|
|
|
- />
|
|
|
- )}
|
|
|
+ {/* Chat Content - con scroll interno */}
|
|
|
+ <div ref={chatContainerRef} className="flex-1 overflow-y-auto p-6 space-y-6">
|
|
|
+ {/* Completed Banner */}
|
|
|
+ {showCompletedBanner && (
|
|
|
+ <CompletedBanner
|
|
|
+ isGeneratingReport={isGeneratingReport}
|
|
|
+ onDismiss={dismissCompletedBanner}
|
|
|
+ />
|
|
|
+ )}
|
|
|
|
|
|
- {/* Messages */}
|
|
|
- <ChatMessages
|
|
|
- messages={messages}
|
|
|
- isLoading={isLoading}
|
|
|
- showDynamicSuggestions={showDynamicSuggestions}
|
|
|
- />
|
|
|
-
|
|
|
- {/* Dynamic Suggestions */}
|
|
|
- {showDynamicSuggestions && currentSuggestions.length > 0 && !isLoading && (
|
|
|
- <DynamicSuggestions
|
|
|
- suggestions={currentSuggestions}
|
|
|
- onSuggestionClick={handleSuggestionClick}
|
|
|
- isLoading={isLoading}
|
|
|
- />
|
|
|
- )}
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ {/* Welcome Message */}
|
|
|
+ {messages.length === 0 && (
|
|
|
+ <WelcomeMessage maxMessages={MAX_MESSAGES} chatType={chatType} />
|
|
|
+ )}
|
|
|
|
|
|
- {/* Input Area */}
|
|
|
- {(chatType === "psychological" || messageCount < MAX_MESSAGES) && (
|
|
|
- <ChatInput
|
|
|
- inputMessage={inputMessage}
|
|
|
- setInputMessage={setInputMessage}
|
|
|
- onSendMessage={handleSendMessage}
|
|
|
- isLimitReached={chatType === "medical" && messageCount >= MAX_MESSAGES}
|
|
|
- isLoading={isLoading || inputDisabledForSuggestions}
|
|
|
- chatType={chatType}
|
|
|
- onEndConversation={chatType === "psychological" ? handleResetClick : undefined}
|
|
|
- hasMessages={messages.length > 0}
|
|
|
+ {/* Suggested Prompts - solo para chat médico */}
|
|
|
+ {chatType === "medical" && showSuggestions && messages.length === 0 && (
|
|
|
+ <SuggestedPrompts
|
|
|
+ onSuggestionClick={handleSuggestionClick}
|
|
|
+ isLoading={isLoading}
|
|
|
/>
|
|
|
)}
|
|
|
|
|
|
- {/* Reset Button - solo para médico */}
|
|
|
- {chatType === "medical" && messageCount >= MAX_MESSAGES && (
|
|
|
- <ResetButton onReset={handleResetWithReportAndModal} />
|
|
|
+ {/* Messages */}
|
|
|
+ <ChatMessages
|
|
|
+ messages={messages}
|
|
|
+ isLoading={isLoading}
|
|
|
+ showDynamicSuggestions={showDynamicSuggestions}
|
|
|
+ chatContainerRef={chatContainerRef}
|
|
|
+ />
|
|
|
+
|
|
|
+ {/* Dynamic Suggestions */}
|
|
|
+ {showDynamicSuggestions && currentSuggestions.length > 0 && !isLoading && (
|
|
|
+ <DynamicSuggestions
|
|
|
+ suggestions={currentSuggestions}
|
|
|
+ onSuggestionClick={handleSuggestionClick}
|
|
|
+ isLoading={isLoading}
|
|
|
+ chatContainerRef={chatContainerRef}
|
|
|
+ />
|
|
|
)}
|
|
|
</div>
|
|
|
+
|
|
|
+ {/* Input Area */}
|
|
|
+ {(chatType === "psychological" || messageCount < MAX_MESSAGES) && (
|
|
|
+ <ChatInput
|
|
|
+ inputMessage={inputMessage}
|
|
|
+ setInputMessage={setInputMessage}
|
|
|
+ onSendMessage={handleSendMessage}
|
|
|
+ isLimitReached={chatType === "medical" && messageCount >= MAX_MESSAGES}
|
|
|
+ isLoading={isLoading || inputDisabledForSuggestions}
|
|
|
+ chatType={chatType}
|
|
|
+ onEndConversation={chatType === "psychological" ? handleResetClick : undefined}
|
|
|
+ hasMessages={messages.length > 0}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+
|
|
|
+ {/* Reset Button - solo para médico */}
|
|
|
+ {chatType === "medical" && messageCount >= MAX_MESSAGES && (
|
|
|
+ <ResetButton onReset={handleResetWithReportAndModal} />
|
|
|
+ )}
|
|
|
</div>
|
|
|
</div>
|
|
|
|