From aaa2dc1100f38fb8c635fc351997d1324376eff8 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 9 Sep 2025 11:17:50 -0500 Subject: [PATCH] Add Scroll to Bottom button to chat UI --- src/components/Shakespeare/ChatPane.tsx | 53 ++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 6ba81fbb..c1bd508d 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -3,7 +3,7 @@ import { useSearchParams } from 'react-router-dom'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; import { Skeleton } from '@/components/ui/skeleton'; -import { Send, Square, Loader2 } from 'lucide-react'; +import { Send, Square, Loader2, ChevronDown } from 'lucide-react'; import { useAISettings } from '@/hooks/useAISettings'; import { useFS } from '@/hooks/useFS'; import { useCurrentUser } from '@/hooks/useCurrentUser'; @@ -68,6 +68,7 @@ export const ChatPane = forwardRef(({ }, ref) => { const [input, setInput] = useState(''); const [systemPrompt, setSystemPrompt] = useState(''); + const [showScrollToBottom, setShowScrollToBottom] = useState(false); // Use external state if provided, otherwise default to false const isBuildLoading = externalIsBuildLoading || false; @@ -210,7 +211,38 @@ export const ChatPane = forwardRef(({ ] }); + // 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 = () => { + if (scrollAreaRef.current) { + scrollAreaRef.current.scrollTop = scrollAreaRef.current.scrollHeight; + } + }; + + // Add scroll event listener + useEffect(() => { + const container = scrollAreaRef.current; + if (!container) return; + + container.addEventListener('scroll', checkScrollPosition); + + // Check initial position + checkScrollPosition(); + + return () => { + container.removeEventListener('scroll', checkScrollPosition); + }; + }, []); useEffect(() => { if (scrollAreaRef.current && (messages || streamingMessage)) { @@ -223,6 +255,9 @@ export const ChatPane = forwardRef(({ if (isNearBottom) { container.scrollTop = container.scrollHeight; } + + // Update scroll button visibility + checkScrollPosition(); } }, [messages, streamingMessage, isLoading]); @@ -291,7 +326,7 @@ export const ChatPane = forwardRef(({ return ( -
+
@@ -353,6 +388,20 @@ export const ChatPane = forwardRef(({
+ {/* Scroll to bottom button */} + {showScrollToBottom && ( +
+ +
+ )} +
{/* Chat Input Container */}