diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 5b7ba475..73b4f4fe 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -75,6 +75,7 @@ export const ChatPane = forwardRef(({ const [attachedFiles, setAttachedFiles] = useState([]); const [isDragOver, setIsDragOver] = useState(false); const { toast } = useToast(); + const [scrolledProjects] = useState(() => new Set()); // Use external state if provided, otherwise default to false const isBuildLoading = externalIsBuildLoading || false; @@ -239,16 +240,6 @@ export const ChatPane = forwardRef(({ } }, [addRecentlyUsedModel, isConfigured, providerModel, searchParams, setSearchParams, startGeneration]); - // Function to check if user is at the bottom of the scroll area - const checkScrollPosition = () => { - if (!scrollAreaRef.current) return; - - const container = scrollAreaRef.current; - const threshold = 100; // 100px threshold - const isNearBottom = container.scrollTop + container.clientHeight >= container.scrollHeight - threshold; - - setShowScrollToBottom(!isNearBottom && container.scrollHeight > container.clientHeight); - }; // Function to scroll to bottom const scrollToBottom = () => { @@ -257,20 +248,28 @@ export const ChatPane = forwardRef(({ } }; - // Add scroll event listener + // Simple scroll event listener useEffect(() => { const container = scrollAreaRef.current; if (!container) return; - container.addEventListener('scroll', checkScrollPosition); + const handleScroll = () => { + const threshold = 100; + const isNearBottom = container.scrollTop + container.clientHeight >= container.scrollHeight - threshold; + const hasScrollableContent = container.scrollHeight > container.clientHeight; - // Check initial position - checkScrollPosition(); + setShowScrollToBottom(!isNearBottom && hasScrollableContent); + }; + + container.addEventListener('scroll', handleScroll); + + // Check immediately + handleScroll(); return () => { - container.removeEventListener('scroll', checkScrollPosition); + container.removeEventListener('scroll', handleScroll); }; - }, []); + }, [messages]); // Re-run when messages change to ensure proper setup useEffect(() => { if (scrollAreaRef.current && (messages || streamingMessage)) { @@ -284,11 +283,34 @@ export const ChatPane = forwardRef(({ container.scrollTop = container.scrollHeight; } - // Update scroll button visibility - checkScrollPosition(); } }, [messages, streamingMessage, isLoading]); + // Scroll to bottom when first visiting a project (including page refresh) + useEffect(() => { + if (projectId && !scrolledProjects.has(projectId)) { + // Small delay to ensure messages have loaded + const timer = setTimeout(() => { + scrollToBottom(); + scrolledProjects.add(projectId); + }, 100); + + return () => clearTimeout(timer); + } + }, [projectId, scrolledProjects]); + + // Also scroll on initial mount if we have a projectId + useEffect(() => { + if (projectId && !scrolledProjects.has(projectId)) { + const timer = setTimeout(() => { + scrollToBottom(); + scrolledProjects.add(projectId); + }, 100); + + return () => clearTimeout(timer); + } + }, []); // Empty dependency array = runs on mount + const handleFileSelect = (file: File) => { setAttachedFiles(prev => [...prev, file]); }; @@ -605,7 +627,7 @@ export const ChatPane = forwardRef(({
{/* Chat Input Container */}
(({ onPaste={handlePaste} onFocus={handleFirstInteraction} placeholder={providerModel.trim() ? "Ask me to add features, edit files, or build your project..." : "Please select a model to start chatting..."} - className="min-h-[52px] max-h-32 resize-none border-0 bg-transparent px-4 py-3 pb-12 text-sm focus-visible:ring-0 focus-visible:ring-offset-0 placeholder:text-muted-foreground" + className="flex-1 resize-none border-0 bg-transparent px-4 py-3 text-sm focus-visible:ring-0 focus-visible:ring-offset-0 placeholder:text-muted-foreground" disabled={isLoading || !providerModel.trim()} rows={1} aria-label="Chat message input" @@ -636,7 +658,7 @@ export const ChatPane = forwardRef(({ /> {/* Bottom Controls Row */} -
+
{/* File Attachment */}