Skip to content

Commit

Permalink
Emit signal if attachmenets list changed
Browse files Browse the repository at this point in the history
Co-authored-by: David L. Qiu <[email protected]>
  • Loading branch information
brichet and dlqqq committed Feb 6, 2025
1 parent 8137b13 commit 104709d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/jupyter-chat/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,30 +556,30 @@ export class ChatModel implements IChatModel {
/**
* Add attachment to send with next message.
*/
addAttachment = (attachment: IAttachment, emit: boolean = true): void => {
const index = this.inputAttachments.findIndex(
addAttachment = (attachment: IAttachment): void => {
const duplicateAttachment = this.inputAttachments.find(
att => att.type === attachment.type && att.value === attachment.value
);
if (index > -1) {
this.inputAttachments.splice(index, 1, attachment);
} else {
this.inputAttachments.push(attachment);
}
if (emit) {
this._inputAttachmentsChanges.emit([...this.inputAttachments]);
if (duplicateAttachment) {
return;
}

this.inputAttachments.push(attachment);
this._inputAttachmentsChanges.emit([...this.inputAttachments]);
};

/**
* Remove attachment to be sent.
*/
removeAttachment = (attachment: IAttachment): void => {
const index = this.inputAttachments.findIndex(
const attachmentIndex = this.inputAttachments.findIndex(
att => att.type === attachment.type && att.value === attachment.value
);
if (index > -1) {
this.inputAttachments.splice(index, 1);
if (attachmentIndex === -1) {
return;
}

this.inputAttachments.splice(attachmentIndex, 1);
this._inputAttachmentsChanges.emit([...this.inputAttachments]);
};

Expand Down

0 comments on commit 104709d

Please sign in to comment.