diff --git a/components/chat-scroll-anchor.tsx b/components/chat-scroll-anchor.tsx
deleted file mode 100644
index 29b6c21..0000000
--- a/components/chat-scroll-anchor.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-'use client'
-
-import * as React from 'react'
-import { useInView } from 'react-intersection-observer'
-import { useAtBottom } from '@/lib/hooks/use-at-bottom'
-
-interface ChatScrollAnchorProps {
- trackVisibility?: boolean
-}
-
-export function ChatScrollAnchor({ trackVisibility }: ChatScrollAnchorProps) {
- const isAtBottom = useAtBottom()
- const { ref, entry, inView } = useInView({
- trackVisibility,
- delay: 100,
- rootMargin: '0px 0px -125px 0px'
- })
-
- React.useEffect(() => {
- if (isAtBottom && trackVisibility && !inView) {
- entry?.target.scrollIntoView({
- block: 'start'
- })
- }
- }, [inView, entry, isAtBottom, trackVisibility])
-
- return
-}
diff --git a/components/chat.tsx b/components/chat.tsx
index 2b7cc20..a8d188f 100644
--- a/components/chat.tsx
+++ b/components/chat.tsx
@@ -4,13 +4,13 @@ import { cn } from '@/lib/utils'
import { ChatList } from '@/components/chat-list'
import { ChatPanel } from '@/components/chat-panel'
import { EmptyScreen } from '@/components/empty-screen'
-import { ChatScrollAnchor } from '@/components/chat-scroll-anchor'
import { useLocalStorage } from '@/lib/hooks/use-local-storage'
import { useEffect, useState } from 'react'
import { useUIState, useAIState } from 'ai/rsc'
import { Session } from '@/lib/types'
import { usePathname, useRouter } from 'next/navigation'
import { Message } from '@/lib/chat/actions'
+import { useScrollAnchor } from '@/lib/hooks/use-scroll-anchor'
import { toast } from 'sonner'
export interface ChatProps extends React.ComponentProps<'div'> {
@@ -26,7 +26,6 @@ export function Chat({ id, className, session, missingKeys }: ChatProps) {
const [input, setInput] = useState('')
const [messages] = useUIState()
const [aiState] = useAIState()
- const isLoading = true
const [_, setNewChatId] = useLocalStorage('newChatId', id)
@@ -55,19 +54,32 @@ export function Chat({ id, className, session, missingKeys }: ChatProps) {
})
}, [missingKeys])
+ const { messagesRef, scrollRef, visibilityRef, isAtBottom, scrollToBottom } =
+ useScrollAnchor()
+
return (
- <>
-
+
+
{messages.length ? (
- <>
-
-
- >
+
) : (
-
+
)}
+
-
- >
+
+
)
}
diff --git a/components/empty-screen.tsx b/components/empty-screen.tsx
index 663f751..bb70d95 100644
--- a/components/empty-screen.tsx
+++ b/components/empty-screen.tsx
@@ -19,7 +19,7 @@ const exampleMessages = [
}
]
-export function EmptyScreen({ setInput }: Pick
) {
+export function EmptyScreen() {
return (
diff --git a/components/sidebar-item.tsx b/components/sidebar-item.tsx
index d5d27a0..fc7020b 100644
--- a/components/sidebar-item.tsx
+++ b/components/sidebar-item.tsx
@@ -60,12 +60,12 @@ export function SidebarItem({ index, chat, children }: SidebarItemProps) {
tabIndex={-1}
className="focus:bg-muted focus:ring-1 focus:ring-ring"
>
-
+
This is a shared chat.
) : (
-
+
)}
-
@@ -103,7 +103,7 @@ export function BotCard({
>
-
{children}
+
{children}
)
}
diff --git a/components/stocks/stock-purchase.tsx b/components/stocks/stock-purchase.tsx
index f0877f8..8acb8e3 100644
--- a/components/stocks/stock-purchase.tsx
+++ b/components/stocks/stock-purchase.tsx
@@ -118,7 +118,7 @@ export function Purchase({