feat: add auto-scroll functionality to ScrollContainer and disable auto-scroll after report completed

This commit is contained in:
Jiang Feng 2025-04-27 15:45:53 +08:00
parent f35131da19
commit 5f22cfc124
3 changed files with 18 additions and 1 deletions

View File

@ -76,6 +76,7 @@ export function MessageListView({
<ScrollContainer
className={cn("flex h-full w-full flex-col overflow-hidden", className)}
scrollShadowColor="var(--app-background)"
autoScrollToBottom
>
<ul className="flex flex-col">
{messageIds.map((messageId) => (

View File

@ -133,6 +133,7 @@ export function ResearchBlock({
<ScrollContainer
className="px-5pb-20 h-full"
scrollShadowColor="var(--card)"
autoScrollToBottom={!hasReport || reportStreaming}
>
{reportId && researchId && (
<ResearchReportBlock
@ -149,7 +150,11 @@ export function ResearchBlock({
forceMount
hidden={activeTab !== "activities"}
>
<ScrollContainer className="h-full" scrollShadowColor="var(--card)">
<ScrollContainer
className="h-full"
scrollShadowColor="var(--card)"
autoScrollToBottom={!hasReport || reportStreaming}
>
{researchId && (
<ResearchActivitiesBlock
className="mt-4"

View File

@ -1,6 +1,7 @@
// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
// SPDX-License-Identifier: MIT
import { useEffect } from "react";
import { useStickToBottom } from "use-stick-to-bottom";
import { ScrollArea } from "~/components/ui/scroll-area";
@ -11,15 +12,25 @@ export function ScrollContainer({
children,
scrollShadow = true,
scrollShadowColor = "var(--background)",
autoScrollToBottom = false,
}: {
className?: string;
children?: React.ReactNode;
scrollShadow?: boolean;
scrollShadowColor?: string;
autoScrollToBottom?: boolean;
}) {
const { scrollRef, contentRef } = useStickToBottom({
initial: "instant",
});
useEffect(() => {
if (!autoScrollToBottom) {
scrollRef.current = null;
contentRef.current = null;
}
}, [autoScrollToBottom, contentRef, scrollRef]);
return (
<div className={cn("relative", className)}>
{scrollShadow && (