Skip to content

Commit

Permalink
refactor: loading animation style
Browse files Browse the repository at this point in the history
  • Loading branch information
longy2k committed Feb 5, 2024
1 parent 020bf98 commit 385fb3a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/components/FetchModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export async function ollamaFetchData(settings: BMOSettings, index: number) {

const messageBlock = targetBotMessage?.querySelector('.messageBlock');
const loadingEl = targetBotMessage?.querySelector("#loading");

if (messageBlock) {
if (loadingEl) {
targetBotMessage?.removeChild(loadingEl);
Expand Down
34 changes: 5 additions & 29 deletions src/components/chat/BotMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { marked } from "marked";
import { prismHighlighting } from "../PrismaHighlighting";
import { addParagraphBreaks } from "./Message";

let loadingAnimationIntervalId: string | number | NodeJS.Timeout | undefined;

export function displayBotMessage(settings: BMOSettings, messageHistory: { role: string; content: string }[], message: string) {
const botMessageDiv = document.createElement("div");
botMessageDiv.className = "botMessage";
Expand Down Expand Up @@ -87,8 +85,11 @@ export function displayLoadingBotMessage(settings: BMOSettings) {

const loadingEl = document.createElement("span");
loadingEl.setAttribute("id", "loading");
loadingEl.style.display = "inline-block";
loadingEl.textContent = "...";
for (let i = 0; i < 3; i++) {
const dotSpan = document.createElement("span");
dotSpan.textContent = ".";
loadingEl.appendChild(dotSpan);
}

botMessageToolBarDiv.appendChild(botNameSpan);
botMessageDiv.appendChild(botMessageToolBarDiv);
Expand All @@ -97,30 +98,5 @@ export function displayLoadingBotMessage(settings: BMOSettings) {
// Dispaly loading animation
botMessageDiv.appendChild(loadingEl);

// Function to update the loading animation
const updateLoadingAnimation = () => {
const loadingEl = document.querySelector('#loading');
if (!loadingEl) {
return;
}
loadingEl.textContent += ".";
// Reset to one dot if the animation has reached three dots
if (loadingEl.textContent && loadingEl.textContent.length > 3) {
loadingEl.textContent = ".";
}
};

// Function to start or restart the loading animation
const loadingElementAnimation = () => {
// Clear any existing interval to prevent speeding up
if (loadingAnimationIntervalId !== undefined) {
clearInterval(loadingAnimationIntervalId);
}
// Set a new interval and store its ID
loadingAnimationIntervalId = setInterval(updateLoadingAnimation, 500);
};

loadingElementAnimation();

return botMessageDiv;
}
42 changes: 41 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,54 @@ button.regenerate-button {

#loading {
color: white;
background-color: gray;
background-color: #808080;
padding: 0px 5px 12px 5px;
border-radius: 5px;
display: none;
line-height: 10px;
font-size: 25px;
font-weight: bolder;
margin: 5px 0px;
display: inline-block;
overflow: hidden;
white-space: nowrap;
}

.theme-light #loading {
color: white;
background-color: #b0b0b0;
}

@keyframes blink {
0%,
100% {
opacity: 1;
}
49.9% {
opacity: 1;
}
50% {
opacity: 0;
}
50.1% {
opacity: 0;
}
}

#loading span {
animation: blink 1.3s infinite both;
}

#loading span:nth-child(1) {
animation-delay: 0s;
}

#loading span:nth-child(2) {
animation-delay: 0.2s;
}

#loading span:nth-child(3) {
animation-delay: 0.4s;
}

.dotIndicator {
Expand Down

0 comments on commit 385fb3a

Please sign in to comment.