Skip to content

Commit

Permalink
adding the ability to use custom html to loading messages
Browse files Browse the repository at this point in the history
  • Loading branch information
OvidijusParsiunas committed Sep 4, 2024
1 parent e92c54e commit c6e204e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions component/src/utils/loading/loadingStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {CustomStyle} from '../../types/styles';

export class LoadingStyle {
public static readonly BUBBLE_CLASS = 'deep-chat-loading-message-bubble';
public static readonly DOTS_CONTAINER_CLASS = 'deep-chat-loading-message-dots-container';

private static colorToHex(color: string) {
const dummyElement = document.createElement('div');
Expand Down
2 changes: 1 addition & 1 deletion component/src/views/chat/messages/messages.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
margin-bottom: 10px;
}

.deep-chat-loading-message-bubble {
.deep-chat-loading-message-dots-container {
width: 1em;
padding-top: 0.6em;
padding-bottom: 0.6em;
Expand Down
17 changes: 13 additions & 4 deletions component/src/views/chat/messages/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,26 @@ export class Messages extends MessagesBase {
if (this.isLastMessageError()) MessageUtils.getLastMessageElement(this.elementRef).remove();
}

public addLoadingMessage() {
if (!this._displayLoadingMessage) return;
private addDefaultLoadingMessage() {
const messageElements = this.createMessageElements('', MessageUtils.AI_ROLE);
const {outerContainer, bubbleElement} = messageElements;
bubbleElement.classList.add(LoadingStyle.BUBBLE_CLASS);
messageElements.bubbleElement.classList.add(LoadingStyle.DOTS_CONTAINER_CLASS);
const dotsElement = document.createElement('div');
dotsElement.classList.add('loading-message-dots');
bubbleElement.appendChild(dotsElement);
this.applyCustomStyles(messageElements, MessageUtils.AI_ROLE, false, this.messageStyles?.loading?.message?.styles);
LoadingStyle.setDots(bubbleElement, this.messageStyles);
this.elementRef.appendChild(outerContainer);
return messageElements;
}

public addLoadingMessage() {
if (!this._displayLoadingMessage) return;
const html = this.messageStyles?.loading?.message?.html;
const messageElements = html
? HTMLMessages.createElements(this, html, MessageUtils.AI_ROLE, true)
: this.addDefaultLoadingMessage();
messageElements.bubbleElement.classList.add(LoadingStyle.BUBBLE_CLASS);
this.applyCustomStyles(messageElements, MessageUtils.AI_ROLE, false, this.messageStyles?.loading?.message?.styles);
ElementUtils.scrollToBottom(this.elementRef);
}

Expand Down

0 comments on commit c6e204e

Please sign in to comment.