mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
Move useAutoScroll hook to SessionDetail and pass scroll functions to children
This commit is contained in:
1 parent
1204cbace9
commit
494d2907fa
2 files changed
+17
-22
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import { memo, useRef, useEffect } from 'react'
|
||||
import { useMessages } from '@/hooks/useOpenCode'
|
||||
import { useAutoScroll } from '@/hooks/useAutoScroll'
|
||||
import { MessagePart } from './MessagePart'
|
||||
import type { MessageWithParts } from '@/api/types'
|
||||
|
||||
@@ -17,8 +16,9 @@ interface MessageThreadProps {
|
||||
sessionID: string
|
||||
directory?: string
|
||||
onFileClick?: (filePath: string, lineNumber?: number) => void
|
||||
containerRef?: React.RefObject<HTMLDivElement | null>
|
||||
onScrollStateChange?: (isScrolledUp: boolean) => void
|
||||
scrollToBottom: () => void
|
||||
setFollowing: (following: boolean) => void
|
||||
isFollowing: () => boolean
|
||||
}
|
||||
|
||||
const isMessageStreaming = (msg: MessageWithParts): boolean => {
|
||||
@@ -31,24 +31,18 @@ const isMessageThinking = (msg: MessageWithParts): boolean => {
|
||||
return msg.parts.length === 0 && isMessageStreaming(msg)
|
||||
}
|
||||
|
||||
export const MessageThread = memo(function MessageThread({ opcodeUrl, sessionID, directory, onFileClick, containerRef, onScrollStateChange }: MessageThreadProps) {
|
||||
export const MessageThread = memo(function MessageThread({ opcodeUrl, sessionID, directory, onFileClick, scrollToBottom, setFollowing, isFollowing }: MessageThreadProps) {
|
||||
const { data: messages, isLoading, error } = useMessages(opcodeUrl, sessionID, directory)
|
||||
const hasInitialScrolledRef = useRef(false)
|
||||
const lastMessageCountRef = useRef(0)
|
||||
|
||||
const { scrollToBottom, setFollowing, isFollowing } = useAutoScroll({
|
||||
containerRef,
|
||||
dependency: sessionID,
|
||||
onScrollStateChange
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
hasInitialScrolledRef.current = false
|
||||
lastMessageCountRef.current = 0
|
||||
}, [sessionID])
|
||||
|
||||
useEffect(() => {
|
||||
if (!containerRef?.current || !messages) return
|
||||
if (!messages) return
|
||||
|
||||
const currentCount = messages.length
|
||||
const prevCount = lastMessageCountRef.current
|
||||
@@ -72,7 +66,7 @@ export const MessageThread = memo(function MessageThread({ opcodeUrl, sessionID,
|
||||
if (isFollowing()) {
|
||||
scrollToBottom()
|
||||
}
|
||||
}, [messages, containerRef, scrollToBottom, setFollowing, isFollowing])
|
||||
}, [messages, scrollToBottom, setFollowing, isFollowing])
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
|
||||
@@ -17,6 +17,7 @@ import { useSettings } from "@/hooks/useSettings";
|
||||
import { useKeyboardShortcuts } from "@/hooks/useKeyboardShortcuts";
|
||||
import { useSettingsDialog } from "@/hooks/useSettingsDialog";
|
||||
import { usePermissionRequests } from "@/hooks/usePermissionRequests";
|
||||
import { useAutoScroll } from "@/hooks/useAutoScroll";
|
||||
import { useEffect, useRef, useCallback } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import type { PermissionResponse } from "@/api/types";
|
||||
@@ -33,6 +34,12 @@ export function SessionDetail() {
|
||||
const [selectedFilePath, setSelectedFilePath] = useState<string | undefined>();
|
||||
const [showScrollButton, setShowScrollButton] = useState(false);
|
||||
|
||||
const { scrollToBottom, setFollowing, isFollowing } = useAutoScroll({
|
||||
containerRef: messageContainerRef,
|
||||
dependency: sessionId,
|
||||
onScrollStateChange: setShowScrollButton
|
||||
});
|
||||
|
||||
const { data: repo, isLoading: repoLoading } = useQuery({
|
||||
queryKey: ["repo", repoId],
|
||||
queryFn: () => getRepo(repoId),
|
||||
@@ -112,13 +119,6 @@ const { currentPermission, pendingCount, dismissPermission } = usePermissionRequ
|
||||
setSelectedFilePath(undefined)
|
||||
}, []);
|
||||
|
||||
const handleScrollToBottom = useCallback(() => {
|
||||
if (messageContainerRef.current) {
|
||||
messageContainerRef.current.scrollTop = messageContainerRef.current.scrollHeight;
|
||||
setShowScrollButton(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handlePermissionResponse = useCallback(async (
|
||||
permissionID: string,
|
||||
permissionSessionID: string,
|
||||
@@ -177,8 +177,9 @@ const { currentPermission, pendingCount, dismissPermission } = usePermissionRequ
|
||||
sessionID={sessionId}
|
||||
directory={repoDirectory}
|
||||
onFileClick={handleFileClick}
|
||||
containerRef={messageContainerRef}
|
||||
onScrollStateChange={setShowScrollButton}
|
||||
scrollToBottom={scrollToBottom}
|
||||
setFollowing={setFollowing}
|
||||
isFollowing={isFollowing}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
@@ -190,7 +191,7 @@ const { currentPermission, pendingCount, dismissPermission } = usePermissionRequ
|
||||
sessionID={sessionId}
|
||||
disabled={!isConnected}
|
||||
showScrollButton={showScrollButton}
|
||||
onScrollToBottom={handleScrollToBottom}
|
||||
onScrollToBottom={scrollToBottom}
|
||||
onShowModelsDialog={() => setModelDialogOpen(true)}
|
||||
onShowSessionsDialog={() => setSessionsDialogOpen(true)}
|
||||
onShowHelpDialog={() => {
|
||||
|
||||
Reference in new issue
Block a user