Skip to content

Commit

Permalink
fixing history loading spinner bug where if the last element was not …
Browse files Browse the repository at this point in the history
…the spinner, the full screen spinner was not changed to smaller one
  • Loading branch information
OvidijusParsiunas committed Dec 25, 2024
1 parent 415f64f commit e3c5026
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion component/src/views/chat/messages/history/loadingHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,22 @@ export class LoadingHistory {
return messageElements;
}

public static changeFullViewToSmall(messages: MessagesBase, messageElements?: MessageElements) {
private static tryChangeViewToSmall(messages: MessagesBase, messageElements?: MessageElements) {
if (messageElements?.outerContainer.classList.contains(LoadingHistory.FULL_VIEW_CLASS)) {
messageElements.outerContainer.classList.replace(LoadingHistory.FULL_VIEW_CLASS, LoadingHistory.SMALL_CLASS);
const styles = messages.messageStyles?.loading?.history?.small?.styles;
if (styles) LoadingHistory.apply(messages, messageElements, styles);
const html = messages.messageStyles?.loading?.history?.small?.html;
if (html) messageElements.bubbleElement.innerHTML = html;
return true;
}
return false;
}

public static changeFullViewToSmall(messages: MessagesBase) {
const lastElement = messages.messageElementRefs[messages.messageElementRefs.length - 1];
const isChanged = LoadingHistory.tryChangeViewToSmall(messages, lastElement);
// last element is usually sufficient, however in demo the full view element is added before other elements
if (!isChanged) LoadingHistory.tryChangeViewToSmall(messages, messages.messageElementRefs[0]);
}
}
2 changes: 1 addition & 1 deletion component/src/views/chat/messages/messagesBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class MessagesBase {
public createNewMessageElement(text: string, role: string, isTop = false) {
this._introPanel?.hide();
const lastMessageElements = this.messageElementRefs[this.messageElementRefs.length - 1];
LoadingHistory.changeFullViewToSmall(this, lastMessageElements);
LoadingHistory.changeFullViewToSmall(this);
if (MessagesBase.isTemporaryElement(lastMessageElements)) {
this.revealRoleElementsIfTempRemoved(lastMessageElements, role); // readding role elements to previous message
lastMessageElements.outerContainer.remove();
Expand Down

0 comments on commit e3c5026

Please sign in to comment.