Skip to content

Commit 1d6d140

Browse files
committed
chore(chat): remove default attachment action buttons & fix duplicated messages issue
1 parent 3c6c454 commit 1d6d140

File tree

2 files changed

+6
-53
lines changed

2 files changed

+6
-53
lines changed

src/components/chat/chat-state.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ export class ChatState {
136136
});
137137

138138
if (allowed) {
139-
this.messages = [...this.messages, newMessage];
139+
if (!this.messages.some((msg) => msg.id === newMessage.id)) {
140+
this.messages = [...this.messages, newMessage];
141+
}
140142
this.inputValue = '';
141143
this.inputAttachments = [];
142144
}

src/components/chat/message-attachments.ts

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ export default class IgcMessageAttachmentsComponent extends LitElement {
5555
registerIconFromText('more', moreIcon, 'material');
5656
}
5757

58-
private openImagePreview(attachment: IgcMessageAttachment) {
59-
this.previewImage = this.getURL(attachment);
60-
}
61-
62-
private closeImagePreview() {
63-
this.previewImage = '';
64-
}
65-
6658
private handleToggle(e: CustomEvent, attachment: IgcMessageAttachment) {
6759
this._chatState?.emitEvent('igcAttachmentClick', { detail: attachment });
6860
e.preventDefault();
@@ -106,34 +98,13 @@ export default class IgcMessageAttachmentsComponent extends LitElement {
10698
</div>`;
10799
}
108100

109-
private renderAttachmentHeaderActions(attachment: IgcMessageAttachment) {
101+
private renderAttachmentHeaderActions() {
110102
return html`<div class="actions">
111103
${this._chatState?.options?.templates?.attachmentActionsTemplate
112104
? this._chatState.options.templates.attachmentActionsTemplate(
113105
this.attachments
114106
)
115-
: html`
116-
<slot name="attachment-actions">
117-
${attachment.type === 'image' ||
118-
attachment.file?.type.startsWith('image/')
119-
? html` <igc-icon-button
120-
name="preview"
121-
collection="material"
122-
variant="flat"
123-
class="small"
124-
tabIndex="-1"
125-
@click=${() => this.openImagePreview(attachment)}
126-
></igc-icon-button>`
127-
: nothing}
128-
<igc-icon-button
129-
name="more"
130-
collection="material"
131-
variant="flat"
132-
class="small"
133-
tabIndex="-1"
134-
></igc-icon-button>
135-
</slot>
136-
`}
107+
: nothing}
137108
</div>`;
138109
}
139110

@@ -170,32 +141,14 @@ export default class IgcMessageAttachmentsComponent extends LitElement {
170141
>
171142
<div slot="title" class="attachment">
172143
${this.renderAttachmentHeaderText(attachment)}
173-
${this.renderAttachmentHeaderActions(attachment)}
144+
${this.renderAttachmentHeaderActions()}
174145
</div>
175146
176147
${this.renderAttachmentContent(attachment)}
177148
</igc-expansion-panel>`
178149
)}`;
179150
}
180151

181-
private renderImagePreview() {
182-
return html` ${this.previewImage
183-
? html`
184-
<div class="image-overlay" @click=${this.closeImagePreview}>
185-
<img class="overlay-image" src=${this.previewImage} />
186-
<igc-icon-button
187-
name="close"
188-
collection="material"
189-
variant="contained"
190-
class="small"
191-
tabIndex="-1"
192-
@click=${this.closeImagePreview}
193-
></igc-icon-button>
194-
</div>
195-
`
196-
: nothing}`;
197-
}
198-
199152
protected override render() {
200153
return html`
201154
<div class="attachments-container">
@@ -205,8 +158,6 @@ export default class IgcMessageAttachmentsComponent extends LitElement {
205158
)
206159
: this.renderDefaultAttachmentsTemplate()}
207160
</div>
208-
209-
${this.renderImagePreview()}
210161
`;
211162
}
212163
}

0 commit comments

Comments
 (0)