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 <ScrollContainer
className={cn("flex h-full w-full flex-col overflow-hidden", className)} className={cn("flex h-full w-full flex-col overflow-hidden", className)}
scrollShadowColor="var(--app-background)" scrollShadowColor="var(--app-background)"
autoScrollToBottom
> >
<ul className="flex flex-col"> <ul className="flex flex-col">
{messageIds.map((messageId) => ( {messageIds.map((messageId) => (

View File

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

View File

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