From dbc91d8a4e22e91e726957d222904c0be4785b23 Mon Sep 17 00:00:00 2001 From: Red Adaya Date: Wed, 1 May 2024 07:17:32 +0800 Subject: [PATCH] use OverlayScrollbarsComponent --- src/app/sidebar/aichat.tsx | 45 +++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/app/sidebar/aichat.tsx b/src/app/sidebar/aichat.tsx index 8a8a5b10..ac5fb866 100644 --- a/src/app/sidebar/aichat.tsx +++ b/src/app/sidebar/aichat.tsx @@ -8,7 +8,8 @@ import { GlobalModel } from "@/models"; import { boundMethod } from "autobind-decorator"; import { If, For } from "tsx-control-statements/components"; import { Markdown } from "@/elements"; -import { OverlayScrollbars } from "overlayscrollbars"; +import type { OverlayScrollbars } from "overlayscrollbars"; +import { OverlayScrollbarsComponent, OverlayScrollbarsComponentRef } from "overlayscrollbars-react"; import "./aichat.less"; @@ -54,30 +55,10 @@ class AIChatKeybindings extends React.Component<{ AIChatObject: AIChat }, {}> { @mobxReact.observer class ChatContent extends React.Component<{}, {}> { chatListKeyCount: number = 0; - containerRef: React.RefObject = React.createRef(); + containerRef: React.RefObject = React.createRef(); chatWindowRef: React.RefObject = React.createRef(); osInstance: OverlayScrollbars = null; - componentDidMount() { - if (this.containerRef.current) { - this.osInstance = OverlayScrollbars( - this.containerRef.current, - { - scrollbars: { autoHide: "leave" }, - }, - { - initialized: (instance) => { - const { viewport } = instance.elements(); - viewport.scrollTo({ - behavior: "auto", - top: this.chatWindowRef.current.scrollHeight, - }); - }, - } - ); - } - } - componentDidUpdate() { if (this.containerRef?.current && this.osInstance) { const { overflowAmount } = this.osInstance.state(); @@ -96,6 +77,16 @@ class ChatContent extends React.Component<{}, {}> { } } + @boundMethod + onScrollbarInitialized(instance) { + this.osInstance = instance; + const { viewport } = instance.elements(); + viewport.scrollTo({ + behavior: "auto", + top: this.chatWindowRef.current.scrollHeight, + }); + } + submitChatMessage(messageStr: string) { const curLine = GlobalModel.inputModel.getCurLine(); const prtn = GlobalModel.submitChatInfoCommand(messageStr, curLine, false); @@ -168,14 +159,19 @@ class ChatContent extends React.Component<{}, {}> { const chatMessageItems = GlobalModel.inputModel.AICmdInfoChatItems.slice(); const chitem: OpenAICmdInfoChatMessageType = null; return ( -
+
{this.renderChatMessage(chitem)}
-
+ ); } } @@ -308,7 +304,6 @@ class AIChat extends React.Component<{}, {}> { render() { const chatMessageItems = GlobalModel.inputModel.AICmdInfoChatItems.slice(); - console.log("chatMessageItems", chatMessageItems); return (