import { useThreadScrolling } from '@/hooks/useThreadScrolling' import { memo } from 'react' import { GenerateResponseButton } from './GenerateResponseButton' import { useMessages } from '@/hooks/useMessages' import { useShallow } from 'zustand/react/shallow' import { useAppearance } from '@/hooks/useAppearance' import { cn } from '@/lib/utils' import { ArrowDown } from 'lucide-react' import { useTranslation } from '@/i18n/react-i18next-compat' import { useAppState } from '@/hooks/useAppState' const ScrollToBottom = ({ threadId, scrollContainerRef, }: { threadId: string scrollContainerRef: React.RefObject }) => { const { t } = useTranslation() const appMainViewBgColor = useAppearance((state) => state.appMainViewBgColor) const { showScrollToBottomBtn, scrollToBottom } = useThreadScrolling(threadId, scrollContainerRef) const { messages } = useMessages( useShallow((state) => ({ messages: state.messages[threadId], })) ) const streamingContent = useAppState((state) => state.streamingContent) const showGenerateAIResponseBtn = (messages[messages.length - 1]?.role === 'user' || (messages[messages.length - 1]?.metadata && 'tool_calls' in (messages[messages.length - 1].metadata ?? {}))) && !streamingContent return (
{showScrollToBottomBtn && (
{ scrollToBottom(true) }} >

{t('scrollToBottom')}

)} {showGenerateAIResponseBtn && ( )}
) } export default memo(ScrollToBottom)