重构组件,优化性能并移除不必要的属性;撤销滚动条修改;

This commit is contained in:
2026-06-03 16:58:10 +08:00
parent fa3e6b6e84
commit 06a3f32d2d
4 changed files with 30 additions and 37 deletions
-21
View File
@@ -30,10 +30,8 @@ export const GlobalChatbox: React.FC<Props> = ({ open, onClose }) => {
);
const bottomRef = useRef<HTMLDivElement>(null);
const workspaceRef = useRef<HTMLDivElement | null>(null);
const composerRef = useRef<AgentComposerHandle | null>(null);
const hasResetForOpenRef = useRef(false);
const shouldAutoScrollRef = useRef(true);
const theme = useTheme();
const currentProjectId = useProjectStore((state) => state.currentProjectId);
@@ -84,20 +82,11 @@ export const GlobalChatbox: React.FC<Props> = ({ open, onClose }) => {
getModel: () => selectedModel,
});
const syncAutoScrollState = useCallback(() => {
const container = workspaceRef.current;
if (!container) return;
const distanceFromBottom =
container.scrollHeight - container.scrollTop - container.clientHeight;
shouldAutoScrollRef.current = distanceFromBottom <= 120;
}, []);
const scrollToBottom = useCallback((behavior: ScrollBehavior = "smooth") => {
bottomRef.current?.scrollIntoView({ behavior });
}, []);
useEffect(() => {
if (!shouldAutoScrollRef.current) return;
scrollToBottom(isStreaming ? "auto" : "smooth");
}, [isStreaming, messages, scrollToBottom]);
@@ -110,7 +99,6 @@ export const GlobalChatbox: React.FC<Props> = ({ open, onClose }) => {
hasResetForOpenRef.current = true;
const timer = window.setTimeout(() => {
shouldAutoScrollRef.current = true;
createSession();
composerRef.current?.clear();
setIsHistoryOpen(false);
@@ -122,14 +110,12 @@ export const GlobalChatbox: React.FC<Props> = ({ open, onClose }) => {
const handleSend = useCallback((prompt: string) => {
if (isStreaming) return;
shouldAutoScrollRef.current = true;
void sendPrompt(prompt);
}, [isStreaming, sendPrompt]);
const handleNewConversation = useCallback(() => {
handleStopSpeech();
stopListening();
shouldAutoScrollRef.current = true;
createSession();
composerRef.current?.clear();
window.setTimeout(() => {
@@ -144,17 +130,12 @@ export const GlobalChatbox: React.FC<Props> = ({ open, onClose }) => {
const handleSelectSession = useCallback(
(storageSessionId: string) => {
shouldAutoScrollRef.current = true;
composerRef.current?.clear();
void switchSession(storageSessionId);
},
[switchSession],
);
const handleWorkspaceScroll = useCallback(() => {
syncAutoScrollState();
}, [syncAutoScrollState]);
const handleDeleteSession = useCallback(
(storageSessionId: string) => {
void removeSession(storageSessionId);
@@ -334,8 +315,6 @@ export const GlobalChatbox: React.FC<Props> = ({ open, onClose }) => {
branchGroups={branchGroups}
branchTransition={branchTransition}
isStreaming={isStreaming}
scrollContainerRef={workspaceRef}
onScroll={handleWorkspaceScroll}
bottomRef={bottomRef}
speakingMessageId={speakingMessageId}
speechState={speechState}