Skip to content

Commit

Permalink
display loader only before streaming start
Browse files Browse the repository at this point in the history
  • Loading branch information
madeindjs committed Nov 15, 2024
1 parent ce3295b commit 5409016
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template>
<div class="CoreChatbotMessage">
<div class="CoreChatbotMessage" :aria-busy="isLoading">
<CoreChatbotAvatar :initials="initials" />
<div
class="CoreChatbotMessage__content"
:style="{ background: contentBgColor }"
>
<CoreChatbotLoader v-if="isLoading" />
<CoreChatbotLoader v-if="displayLoader" />
<div v-else class="CoreChatbotMessage__content__text">
<BaseMarkdown v-if="useMarkdown" :raw-text="content">
</BaseMarkdown>
Expand Down Expand Up @@ -82,6 +82,10 @@ defineEmits({
const actions = computed<Action[]>(() => props.message?.actions ?? []);
const displayLoader = computed(() => {
return props.isLoading && !content.value;
});
const role = computed(() => {
if (props.isLoading) return "assistant";
return props.message?.role ?? "";
Expand Down
16 changes: 10 additions & 6 deletions src/ui/src/components/core/content/CoreChatbot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ See the stubs for more details.
@action-click="handleActionClick($event)"
/>
<CoreChatbotMessage
v-if="isResponsePending"
v-if="displayExtraLoader"
is-loading
:initials="fields.assistantInitials.value"
/>
Expand Down Expand Up @@ -311,7 +311,7 @@ import type { Message } from "./CoreChatBot/CoreChatbotMessage.vue";
const rootEl: Ref<HTMLElement> = ref(null);
const messageAreaEl: Ref<HTMLElement> = ref(null);
const messagesEl: Ref<HTMLElement> = ref(null);
const isResponsePending: Ref<boolean> = ref(false);
const messageIndexLoading: Ref<number | undefined> = ref(undefined);
const fields = inject(injectionKeys.evaluatedFields);
const files: Ref<File[]> = shallowRef([]);
const isUploadingFiles = ref(false);
Expand All @@ -331,18 +331,22 @@ const isUploadSizeExceeded = computed(() => {
return filesSize >= MAX_FILE_SIZE;
});
const displayExtraLoader = computed(() => {
if (messageIndexLoading.value === undefined) return false;
return messageIndexLoading.value >= messages.value.length;
});
function handleMessageSent() {
if (isResponsePending.value) return;
isResponsePending.value = true;
if (messageIndexLoading.value) return;
messageIndexLoading.value = messages.value.length + 1;
const event = new CustomEvent("wf-chatbot-message", {
detail: {
payload: {
role: "user",
content: outgoingMessage.value,
},
callback: () => {
// TODO: handle start streaming
isResponsePending.value = false;
messageIndexLoading.value = undefined;
},
},
});
Expand Down

0 comments on commit 5409016

Please sign in to comment.