diff --git a/app/layout.tsx b/app/layout.tsx index 153021c..4d366d0 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -40,10 +40,10 @@ export default function RootLayout({ children }: RootLayoutProps) { )} > -
+
{/* @ts-ignore */}
-
{children}
+
{children}
diff --git a/components/button-scroll-to-bottom.tsx b/components/button-scroll-to-bottom.tsx new file mode 100644 index 0000000..9ec0659 --- /dev/null +++ b/components/button-scroll-to-bottom.tsx @@ -0,0 +1,48 @@ +'use client' + +import * as React from 'react' +import { ArrowDown } from 'lucide-react' + +import { cn } from '@/lib/utils' +import { Button, type ButtonProps } from '@/components/ui/button' + +export function ButtonScrollToBottom({ className, ...props }: ButtonProps) { + const [isAtBottom, setIsAtBottom] = React.useState(false) + + React.useEffect(() => { + const handleScroll = () => { + setIsAtBottom( + window.innerHeight + window.scrollY > document.body.offsetHeight - 100 + ) + } + + window.addEventListener('scroll', handleScroll, { passive: true }) + handleScroll() + + return () => { + window.removeEventListener('scroll', handleScroll) + } + }, []) + + return ( + + ) +} diff --git a/components/chat-panel.tsx b/components/chat-panel.tsx index 6189500..f1fa3b2 100644 --- a/components/chat-panel.tsx +++ b/components/chat-panel.tsx @@ -6,6 +6,7 @@ import { RefreshCcw, StopCircle } from 'lucide-react' import { Button } from '@/components/ui/button' import { ExternalLink } from '@/components/external-link' import { PromptForm } from '@/components/prompt-form' +import { ButtonScrollToBottom } from '@/components/button-scroll-to-bottom' export interface ChatPanelProps extends Pick< @@ -24,15 +25,16 @@ export function ChatPanel({ }: ChatPanelProps) { return (
+
-
+
{isLoading ? ( ) : ( @@ -42,13 +44,13 @@ export function ChatPanel({ onClick={() => reload()} className="bg-background" > - + Regenerate response ) )}
-
+
{ append({ @@ -58,7 +60,7 @@ export function ChatPanel({ }} isLoading={isLoading} /> -

+

Open source AI chatbot app built with{' '} Next.js and{' '} diff --git a/components/chat.tsx b/components/chat.tsx index 738ff71..c7fff5d 100644 --- a/components/chat.tsx +++ b/components/chat.tsx @@ -18,7 +18,7 @@ export function Chat({ id, initialMessages }: ChatProps) { }) return ( -

+
-
+
@@ -75,9 +75,9 @@ export function PromptForm({ onSubmit, isLoading }: PromptProps) { onChange={e => setInput(e.target.value)} placeholder="Send a message." spellCheck={false} - className="min-h-[60px] w-full resize-none bg-transparent px-4 py-[1.4rem] focus-within:outline-none sm:text-sm" + className="min-h-[60px] w-full resize-none bg-transparent px-4 py-[1.3rem] focus-within:outline-none sm:text-sm" /> -
+