From 43c7cbb21e465185157f04aa97fc8a32e42afcab Mon Sep 17 00:00:00 2001 From: Jeremy Date: Wed, 20 Mar 2024 04:37:08 +0300 Subject: [PATCH] Improve scroll anchor (#275) --- app/(chat)/layout.tsx | 4 +- components/button-scroll-to-bottom.tsx | 20 +++--- components/chat-list.tsx | 35 +++++++---- components/chat-panel.tsx | 28 ++++++--- components/chat-scroll-anchor.tsx | 28 --------- components/chat.tsx | 34 ++++++---- components/empty-screen.tsx | 2 +- components/sidebar-item.tsx | 4 +- components/stocks/message.tsx | 4 +- components/stocks/stock-purchase.tsx | 2 +- lib/hooks/use-at-bottom.tsx | 23 ------- lib/hooks/use-scroll-anchor.tsx | 86 ++++++++++++++++++++++++++ 12 files changed, 169 insertions(+), 101 deletions(-) delete mode 100644 components/chat-scroll-anchor.tsx delete mode 100644 lib/hooks/use-at-bottom.tsx create mode 100644 lib/hooks/use-scroll-anchor.tsx diff --git a/app/(chat)/layout.tsx b/app/(chat)/layout.tsx index bbdb186..2825d59 100644 --- a/app/(chat)/layout.tsx +++ b/app/(chat)/layout.tsx @@ -8,9 +8,7 @@ export default async function ChatLayout({ children }: ChatLayoutProps) { return (
-
- {children} -
+ {children}
) } diff --git a/components/button-scroll-to-bottom.tsx b/components/button-scroll-to-bottom.tsx index 436a6c0..3988e73 100644 --- a/components/button-scroll-to-bottom.tsx +++ b/components/button-scroll-to-bottom.tsx @@ -3,13 +3,20 @@ import * as React from 'react' import { cn } from '@/lib/utils' -import { useAtBottom } from '@/lib/hooks/use-at-bottom' import { Button, type ButtonProps } from '@/components/ui/button' import { IconArrowDown } from '@/components/ui/icons' -export function ButtonScrollToBottom({ className, ...props }: ButtonProps) { - const isAtBottom = useAtBottom() +interface ButtonScrollToBottomProps extends ButtonProps { + isAtBottom: boolean + scrollToBottom: () => void +} +export function ButtonScrollToBottom({ + className, + isAtBottom, + scrollToBottom, + ...props +}: ButtonScrollToBottomProps) { return (