Skip to content

Commit

Permalink
chat: smoother ux (fixes #7915) (#7931)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
RheuX and dogi authored Dec 16, 2024
1 parent dad08fd commit 56d4b39
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
22 changes: 18 additions & 4 deletions src/app/chat/chat-window/chat-window.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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 ],
Expand Down

0 comments on commit 56d4b39

Please sign in to comment.