Skip to content

Commit

Permalink
feat: chat api support scrollToBottom (#3714)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricbet committed May 24, 2024
1 parent 7fc3354 commit eee60f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/ai-native/src/browser/chat/chat.api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export class ChatService extends Disposable {
private readonly _onChatReplyMessageLaunch = new Emitter<string>();
public readonly onChatReplyMessageLaunch: Event<string> = this._onChatReplyMessageLaunch.event;

private readonly _onScrollToBottom = new Emitter<void>();
public readonly onScrollToBottom: Event<void> = this._onScrollToBottom.event;

constructor() {
super();
this.addDispose(this.msgHistoryManager);
Expand Down Expand Up @@ -51,4 +54,8 @@ export class ChatService extends Disposable {
public getHistoryMessages(): IHistoryChatMessage[] {
return this.msgHistoryManager.getMessages();
}

public scrollToBottom(): void {
this._onScrollToBottom.fire();
}
}
8 changes: 8 additions & 0 deletions packages/ai-native/src/browser/chat/chat.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ export const AIChatView = observer(() => {
React.useEffect(() => {
const disposer = new Disposable();

disposer.addDispose(
chatApiService.onScrollToBottom(() => {
requestAnimationFrame(() => {
scrollToBottom();
});
}),
);

disposer.addDispose(
chatApiService.onChatMessageLaunch(async (message) => {
if (message.immediate !== false) {
Expand Down

0 comments on commit eee60f8

Please sign in to comment.