Compare commits
2 Commits
ca29bd5003
...
chat-scrol
| Author | SHA1 | Date | |
|---|---|---|---|
| 993137068e | |||
| 5755bd3184 |
@@ -1,5 +1,5 @@
|
||||
'use client'
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import { useChat } from '@ai-sdk/react'
|
||||
import { DefaultChatTransport, type UIMessage } from 'ai'
|
||||
import { Button } from '~/components/ui/button'
|
||||
@@ -83,14 +83,21 @@ function AuthenticatedChatInterface({ dbMessages, sessionId }: ChatInterfaceProp
|
||||
sendMessage({ text })
|
||||
}
|
||||
const gsapContext = useGsapContext()
|
||||
const didInitialScroll = useRef(false)
|
||||
useEffect(() => {
|
||||
let scroller = gsapContext?.getScroller()
|
||||
if (scroller instanceof Window) {
|
||||
return;
|
||||
const scroller = gsapContext?.getScroller()
|
||||
if (!scroller || scroller instanceof Window) {
|
||||
return
|
||||
}
|
||||
console.log(scroller?.scrollHeight)
|
||||
scroller?.scrollTo({ behavior: 'smooth', top: scroller.scrollHeight })
|
||||
}, [messages])
|
||||
// Jump instantly on first open so the chat starts pinned to the bottom;
|
||||
// animate subsequent updates. Defer a frame so the messages have laid out
|
||||
// (and any streaming content has grown) before we measure scrollHeight.
|
||||
const behavior: ScrollBehavior = didInitialScroll.current ? 'smooth' : 'auto'
|
||||
didInitialScroll.current = true
|
||||
requestAnimationFrame(() => {
|
||||
scroller.scrollTo({ behavior, top: scroller.scrollHeight })
|
||||
})
|
||||
}, [messages, status])
|
||||
return (
|
||||
<div className="flex flex-col h-full">
|
||||
{messages &&
|
||||
@@ -114,7 +121,7 @@ function AuthenticatedChatInterface({ dbMessages, sessionId }: ChatInterfaceProp
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="p-4 border-t flex flex-row gap-2">
|
||||
<div className="p-4 border-t flex flex-row gap-2 shrink-0">
|
||||
<Textarea
|
||||
name='message'
|
||||
value={input}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ScrollArea } from '~/components/ui/scroll-area';
|
||||
import { memo } from 'react';
|
||||
const Messages = memo(({messages,status}: { messages: UIMessage[],status:ChatStatus}) => {
|
||||
return (
|
||||
<ScrollArea data-scroller-priority='1' className="w-full h-[90%] max-w-4xl mx-auto">
|
||||
<ScrollArea data-scroller-priority='1' className="w-full flex-1 min-h-0 max-w-4xl mx-auto">
|
||||
{messages.map((message, i) => (
|
||||
<Card.AnimatedCard scrollOnly={true} key={i}>
|
||||
<Card.CardContent>
|
||||
|
||||
@@ -9,11 +9,11 @@ export default function ChatPage() {
|
||||
const {messages,session,isLoading,error} = useMessages()
|
||||
useTimeLine(messages)
|
||||
return (
|
||||
<div className="flex flex-col px-10 lg:px-0 w-full h-full max-w-4xl mx-auto pt-10">
|
||||
<div className="flex flex-col px-10 lg:px-0 w-full h-full max-w-4xl mx-auto pt-10 pb-4">
|
||||
<AnimatedPageTitle position={0}>
|
||||
<span>Talk To My </span> <span> AI-Assistant</span>
|
||||
</AnimatedPageTitle>
|
||||
<div className='flex items-center h-[80%] w-full my-auto w-full'>
|
||||
<div className='flex flex-1 min-h-0 w-full'>
|
||||
{!isLoading &&
|
||||
<ChatInterface sessionId={session?.id} dbMessages={messages ?? []}/>
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export default async function RootLayout({
|
||||
<MusicPlayerProvider>
|
||||
<AnimatedBackGroundContainer followSpeed={0.003} particleCount={100} orbitRadius={2000}>
|
||||
<TopNav />
|
||||
<main className="absolute lg:top-10 h-screen lg:h-[calc(100vh-var(--spacing)*10)] w-screen">
|
||||
<main className="absolute lg:top-10 h-[100dvh] lg:h-[calc(100vh-var(--spacing)*10)] w-screen">
|
||||
{children}
|
||||
</main>
|
||||
{modal}
|
||||
|
||||
Reference in New Issue
Block a user