scroll to bottom button

This commit is contained in:
Nate Kelley 2025-08-21 22:17:34 -06:00
parent 6818c46578
commit b29fb18a3c
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
6 changed files with 36 additions and 24 deletions

View File

@ -3,18 +3,20 @@ import { ChevronDown } from '@/components/ui/icons';
import { AppTooltip } from '@/components/ui/tooltip'; import { AppTooltip } from '@/components/ui/tooltip';
import { cn } from '@/lib/classMerge'; import { cn } from '@/lib/classMerge';
export const ReasoningScrollToBottom: React.FC<{ export const ScrollToBottomButton: React.FC<{
isAutoScrollEnabled: boolean; isAutoScrollEnabled: boolean;
scrollToBottom: () => void; scrollToBottom: () => void;
}> = React.memo(({ isAutoScrollEnabled, scrollToBottom }) => { className?: string;
}> = React.memo(({ isAutoScrollEnabled, scrollToBottom, className }) => {
return ( return (
<div <div
data-testid="reasoning-scroll-to-bottom" data-testid="scroll-to-bottom-button"
className={cn( className={cn(
'absolute right-4 bottom-4 z-10 duration-300', 'absolute right-4 bottom-4 z-10 duration-300',
isAutoScrollEnabled isAutoScrollEnabled
? 'pointer-events-none scale-90 opacity-0' ? 'pointer-events-none scale-90 opacity-0'
: 'pointer-events-auto scale-100 cursor-pointer opacity-100' : 'pointer-events-auto scale-100 cursor-pointer opacity-100',
className
)}> )}>
<AppTooltip title="Stick to bottom" sideOffset={12} delayDuration={500}> <AppTooltip title="Stick to bottom" sideOffset={12} delayDuration={500}>
<button <button
@ -30,4 +32,4 @@ export const ReasoningScrollToBottom: React.FC<{
); );
}); });
ReasoningScrollToBottom.displayName = 'ReasoningScrollToBottom'; ScrollToBottomButton.displayName = 'ScrollToBottomButton';

View File

@ -2,7 +2,7 @@
import type { Value, AnyPluginConfig } from 'platejs'; import type { Value, AnyPluginConfig } from 'platejs';
import { Plate, type TPlateEditor } from 'platejs/react'; import { Plate, type TPlateEditor } from 'platejs/react';
import React, { useImperativeHandle, useRef } from 'react'; import React, { useEffect, useImperativeHandle, useRef } from 'react';
import { useDebounceFn, useMemoizedFn } from '@/hooks'; import { useDebounceFn, useMemoizedFn } from '@/hooks';
import { useAutoScroll } from '@/hooks/useAutoScroll'; import { useAutoScroll } from '@/hooks/useAutoScroll';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
@ -13,6 +13,7 @@ import { useReportEditor } from './useReportEditor';
import type { ReportElementsWithIds, ReportElementWithId } from '@buster/server-shared/reports'; import type { ReportElementsWithIds, ReportElementWithId } from '@buster/server-shared/reports';
import { platejsToMarkdown } from './plugins/markdown-kit/platejs-conversions'; import { platejsToMarkdown } from './plugins/markdown-kit/platejs-conversions';
import { ShimmerText } from '@/components/ui/typography/ShimmerText'; import { ShimmerText } from '@/components/ui/typography/ShimmerText';
import { ScrollToBottomButton } from '../buttons/ScrollToBottomButton';
interface ReportEditorProps { interface ReportEditorProps {
// We accept the generic Value type but recommend using ReportTypes.Value for type safety // We accept the generic Value type but recommend using ReportTypes.Value for type safety
@ -69,11 +70,12 @@ export const ReportEditor = React.memo(
const isReady = useRef(false); const isReady = useRef(false);
const editorContainerRef = useRef<HTMLDivElement>(null); const editorContainerRef = useRef<HTMLDivElement>(null);
const { isAutoScrollEnabled } = useAutoScroll(editorContainerRef, { const { isAutoScrollEnabled, enableAutoScroll, disableAutoScroll, scrollToBottom } =
enabled: isStreaming, useAutoScroll(editorContainerRef, {
bottomThreshold: 50, enabled: isStreaming,
observeSubTree: true bottomThreshold: 50,
}); observeSubTree: true
});
const editor = useReportEditor({ const editor = useReportEditor({
isStreaming, isStreaming,
@ -126,6 +128,14 @@ export const ReportEditor = React.memo(
wait: 1500 wait: 1500
}); });
useEffect(() => {
if (isStreaming) {
enableAutoScroll();
} else {
disableAutoScroll();
}
}, [isStreaming]);
if (!editor) return null; if (!editor) return null;
return ( return (
@ -146,6 +156,13 @@ export const ReportEditor = React.memo(
/> />
</ThemeWrapper> </ThemeWrapper>
{postEditorChildren} {postEditorChildren}
{isStreaming && (
<ScrollToBottomButton
isAutoScrollEnabled={isAutoScrollEnabled}
scrollToBottom={scrollToBottom}
className="fixed right-8 bottom-8 z-10"
/>
)}
</EditorContainer> </EditorContainer>
</Plate> </Plate>
); );

View File

@ -15,7 +15,7 @@ export function StreamingText(props: PlateTextProps) {
<PlateText <PlateText
className={cn( className={cn(
'streaming-node', 'streaming-node',
isStreaming && ['animate-highlight-fade'], isStreaming && 'animate-highlight-fade',
// Only show the animated dot on the last streaming text node // Only show the animated dot on the last streaming text node
isLastStreamingText && [ isLastStreamingText && [
'after:ml-1.5 after:inline-block after:h-3 after:w-3 after:animate-pulse after:rounded-full after:bg-purple-500 after:align-middle after:content-[""]' 'after:ml-1.5 after:inline-block after:h-3 after:w-3 after:animate-pulse after:rounded-full after:bg-purple-500 after:align-middle after:content-[""]'

View File

@ -11,7 +11,7 @@ import { ScrollArea } from '@/components/ui/scroll-area';
import { useAutoScroll } from '@/hooks/useAutoScroll'; import { useAutoScroll } from '@/hooks/useAutoScroll';
import { ReasoningMessageSelector } from './ReasoningMessages'; import { ReasoningMessageSelector } from './ReasoningMessages';
import { BlackBoxMessage } from './ReasoningMessages/ReasoningBlackBoxMessage'; import { BlackBoxMessage } from './ReasoningMessages/ReasoningBlackBoxMessage';
import { ReasoningScrollToBottom } from './ReasoningScrollToBottom'; import { ScrollToBottomButton } from '@/components/ui/buttons/ScrollToBottomButton';
import type { BusterChatMessage, IBusterChat } from '@/api/asset_interfaces/chat'; import type { BusterChatMessage, IBusterChat } from '@/api/asset_interfaces/chat';
interface ReasoningControllerProps { interface ReasoningControllerProps {
@ -79,7 +79,7 @@ export const ReasoningController: React.FC<ReasoningControllerProps> = ({ chatId
</div> </div>
</ScrollArea> </ScrollArea>
<ReasoningScrollToBottom <ScrollToBottomButton
isAutoScrollEnabled={isAutoScrollEnabled} isAutoScrollEnabled={isAutoScrollEnabled}
scrollToBottom={scrollToBottom} scrollToBottom={scrollToBottom}
/> />

View File

@ -10,9 +10,7 @@ import { type IReportEditor } from '@/components/ui/report/ReportEditor';
import { ReportEditorSkeleton } from '@/components/ui/report/ReportEditorSkeleton'; import { ReportEditorSkeleton } from '@/components/ui/report/ReportEditorSkeleton';
import { useChatIndividualContextSelector } from '@/layouts/ChatLayout/ChatContext'; import { useChatIndividualContextSelector } from '@/layouts/ChatLayout/ChatContext';
import { useTrackAndUpdateReportChanges } from '@/api/buster-electric/reports/hooks'; import { useTrackAndUpdateReportChanges } from '@/api/buster-electric/reports/hooks';
import { ShimmerText } from '@/components/ui/typography/ShimmerText';
import { GeneratingContent } from './GeneratingContent'; import { GeneratingContent } from './GeneratingContent';
import { useHotkeys } from 'react-hotkeys-hook';
export const ReportPageController: React.FC<{ export const ReportPageController: React.FC<{
reportId: string; reportId: string;

View File

@ -60,21 +60,16 @@
} }
} }
/*
highlightFade animation:
- Animates a highlight background and a bottom border only (no outline).
- The border is only on the bottom, not using outline.
*/
@keyframes highlightFade { @keyframes highlightFade {
0% { 0% {
/* Use highlight background, fallback to brand, then yellow */ /* Use highlight background, fallback to brand, then yellow */
background-color: var(--color-highlight-background, var(--color-purple-100, yellow)); background-color: var(--color-highlight-background, var(--color-purple-100, yellow));
/* Only bottom border is visible at start */ /* Use box-shadow instead of border - doesn't take up space */
border-bottom: 1px solid var(--color-highlight-border, var(--color-purple-200, yellow)); box-shadow: 0 1.5px 0 0 var(--color-highlight-border, var(--color-purple-300, yellow));
} }
100% { 100% {
background-color: var(--color-highlight-to-background, transparent); background-color: var(--color-highlight-to-background, transparent);
border-bottom: 0px solid var(--color-highlight-to-border, transparent); box-shadow: 0 0 0 0 var(--color-highlight-to-border, transparent);
} }
} }