From 56d4b398b9c8fd2732e60eb5ad926a5351f12c45 Mon Sep 17 00:00:00 2001 From: Axel Lo <54468493+RheuX@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:22:56 -0800 Subject: [PATCH] chat: smoother ux (fixes #7915) (#7931) Co-authored-by: dogi --- package.json | 2 +- .../chat/chat-window/chat-window.component.ts | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index e5e7f9ef39..6cfbdb5399 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "planet", "license": "AGPL-3.0", - "version": "0.16.4", + "version": "0.16.5", "myplanet": { "latest": "v0.21.40", "min": "v0.20.40" diff --git a/src/app/chat/chat-window/chat-window.component.ts b/src/app/chat/chat-window/chat-window.component.ts index 85cdf7ce7d..2b987c78cf 100644 --- a/src/app/chat/chat-window/chat-window.component.ts +++ b/src/app/chat/chat-window/chat-window.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit, OnDestroy, ViewChild, ElementRef, ChangeDetectorRef, Input, AfterViewInit } from '@angular/core'; import { FormBuilder, FormGroup } from '@angular/forms'; import { Subject } from 'rxjs'; -import { takeUntil } from 'rxjs/operators'; +import { filter, takeUntil } from 'rxjs/operators'; import { CustomValidators } from '../../validators/custom-validators'; import { ConversationForm, AIProvider } from '../chat.model'; @@ -20,6 +20,7 @@ export class ChatWindowComponent implements OnInit, OnDestroy, AfterViewInit { spinnerOn = true; streaming: boolean; disabled = false; + clearChat = true; provider: AIProvider; conversations: any[] = []; selectedConversationId: any; @@ -71,8 +72,7 @@ export class ChatWindowComponent implements OnInit, OnDestroy, AfterViewInit { this.chatService.newChatSelected$ .pipe(takeUntil(this.onDestroy$)) .subscribe(() => { - this.selectedConversationId = null; - this.conversations = []; + this.resetConversation(); this.focusInput(); }, error => { console.error('Error subscribing to newChatSelected$', error); @@ -81,7 +81,16 @@ export class ChatWindowComponent implements OnInit, OnDestroy, AfterViewInit { subscribeToSelectedConversation() { this.chatService.selectedConversationId$ - .pipe(takeUntil(this.onDestroy$)) + .pipe( + takeUntil(this.onDestroy$), + filter(() => { + if (this.clearChat) { + this.clearChat = false; + return false; + } + return true; + }) + ) .subscribe((conversationId) => { this.selectedConversationId = conversationId; this.fetchConversation(this.selectedConversationId?._id); @@ -102,6 +111,11 @@ export class ChatWindowComponent implements OnInit, OnDestroy, AfterViewInit { })); } + resetConversation() { + this.conversations = []; + this.selectedConversationId = null; + } + createForm() { this.promptForm = this.formBuilder.group({ prompt: [ '', CustomValidators.required ],