Compare commits
3 Commits
5755bd3184
...
blog-scrol
| Author | SHA1 | Date | |
|---|---|---|---|
| d85cc205de | |||
| 95666e20e9 | |||
| 993137068e |
@@ -32,7 +32,7 @@ export default async function BlogPostPage({ params }: Props) {
|
|||||||
const date = typeof parsed.data.date === "string" ? parsed.data.date : post.date;
|
const date = typeof parsed.data.date === "string" ? parsed.data.date : post.date;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="mx-auto max-w-2xl px-4 py-12">
|
<main className="mx-auto h-full max-w-2xl overflow-y-auto px-4 py-12">
|
||||||
<header className="mb-8">
|
<header className="mb-8">
|
||||||
<h1 className="text-3xl font-bold">{title}</h1>
|
<h1 className="text-3xl font-bold">{title}</h1>
|
||||||
{date && (
|
{date && (
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export default async function BlogPage() {
|
|||||||
const posts = await servTrpc.blog.list();
|
const posts = await servTrpc.blog.list();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="mx-auto max-w-2xl px-4 py-12">
|
<main className="mx-auto h-full max-w-2xl overflow-y-auto px-4 py-12">
|
||||||
<h1 className="mb-8 text-3xl font-bold">Blog</h1>
|
<h1 className="mb-8 text-3xl font-bold">Blog</h1>
|
||||||
{posts.length === 0 ? (
|
{posts.length === 0 ? (
|
||||||
<p className="text-muted-foreground">No posts yet.</p>
|
<p className="text-muted-foreground">No posts yet.</p>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect, useRef } from 'react'
|
||||||
import { useChat } from '@ai-sdk/react'
|
import { useChat } from '@ai-sdk/react'
|
||||||
import { DefaultChatTransport, type UIMessage } from 'ai'
|
import { DefaultChatTransport, type UIMessage } from 'ai'
|
||||||
import { Button } from '~/components/ui/button'
|
import { Button } from '~/components/ui/button'
|
||||||
@@ -83,14 +83,21 @@ function AuthenticatedChatInterface({ dbMessages, sessionId }: ChatInterfaceProp
|
|||||||
sendMessage({ text })
|
sendMessage({ text })
|
||||||
}
|
}
|
||||||
const gsapContext = useGsapContext()
|
const gsapContext = useGsapContext()
|
||||||
|
const didInitialScroll = useRef(false)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let scroller = gsapContext?.getScroller()
|
const scroller = gsapContext?.getScroller()
|
||||||
if (scroller instanceof Window) {
|
if (!scroller || scroller instanceof Window) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
console.log(scroller?.scrollHeight)
|
// Jump instantly on first open so the chat starts pinned to the bottom;
|
||||||
scroller?.scrollTo({ behavior: 'smooth', top: scroller.scrollHeight })
|
// animate subsequent updates. Defer a frame so the messages have laid out
|
||||||
}, [messages])
|
// (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 (
|
return (
|
||||||
<div className="flex flex-col h-full">
|
<div className="flex flex-col h-full">
|
||||||
{messages &&
|
{messages &&
|
||||||
|
|||||||
Reference in New Issue
Block a user