Skip to content

Commit

Permalink
Merge pull request #11 from BuonDavide/issue/191-loaders
Browse files Browse the repository at this point in the history
Add Loader on Files / Q&A / Links and Dashboard
  • Loading branch information
stefanorosanelli authored Aug 29, 2024
2 parents d548e6b + fd3fe48 commit 98c0a15
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 51 deletions.
15 changes: 3 additions & 12 deletions components/Dialog/EditMetadata.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,7 @@
</template>
<template v-else>
<div class="h-28 flex">
<svg aria-hidden="true" class="mx-auto mt-4 h-16 animate-spin fill-blue-600" viewBox="0 0 100 101" xmlns="http://www.w3.org/2000/svg">
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
<ElementLoader :loader-dim="64" class="mx-auto" />
</div>
</template>
</div>
Expand Down Expand Up @@ -101,10 +92,10 @@ onBeforeMount(async () => {
const data = await response.json();
docsFound.value = (data?.length || 0) > 0;
metadata.value = data?.[0]?.cmetadata || {};
loaded.value = true;
setTimeout(() => (loaded.value = true), 250);
} catch (err) {
console.log(err);
loaded.value = true;
setTimeout(() => (loaded.value = true), 250);
}
});
Expand Down
13 changes: 7 additions & 6 deletions components/Element/ChatbotFiles.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<template>
<div class="flex flex-col space-y-8">
<div v-if="isLoading" class="mt-16 flex flex-row justify-center">
<ElementLoader :loader-dim="48" />
<span class="sr-only">loading...</span>
</div>
<div v-else class="flex flex-col space-y-8">
<!-- new -->
<div>
<FormChatbotFile v-if="isUploadAllowed" @file-uploaded="loadFiles" />
Expand All @@ -10,9 +14,7 @@
</div>

<!-- existing -->
<div v-if="isLoading" class="-my-6 ellipsis-loading text-sky-800"><span class="sr-only">loading...</span></div>

<div v-else-if="files.length" class="flex flex-col space-y-2.5">
<div v-if="files.length" class="flex flex-col space-y-2.5">
<ElementChatbotFileItem v-for="item in files" :key="item.custom_id" :item="item" :indexed="checkIndexed(item.custom_id)" @file-deleted="loadFiles" />
</div>
</div>
Expand Down Expand Up @@ -58,12 +60,11 @@ const loadFiles = async () => {
files.value = items.data;
indexedItems = await $fetch(`/api/brevia/index/${collection?.uuid}/documents_metadata?filter[type]=files`);
}
isLoading.value = false;
};
await loadFiles();
isLoading.value = false;
isUploadAllowed.value = checkUploadAllowed(files);
setTimeout(() => (isLoading.value = false), 750);
const checkIndexed = (id: string | undefined) => {
if (indexedItems.filter((element: any) => element.custom_id == id).length == 0) {
Expand Down
11 changes: 7 additions & 4 deletions components/Element/ChatbotLinks.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<template>
<div class="flex flex-col space-y-10">
<div v-if="isLoading" class="flex flex-row mt-16 justify-center">
<ElementLoader :loader-dim="48" />
<span class="sr-only">loading...</span>
</div>
<div v-else class="flex flex-col space-y-10">
<!-- new -->

<div v-if="!addMode" class="flex flex-row justify-between">
Expand Down Expand Up @@ -40,8 +44,7 @@
</div>
</div>
<!-- existing -->
<div v-if="isLoading" class="-my-6 ellipsis-loading text-sky-700"><span class="sr-only">loading...</span></div>
<div v-else-if="filteredLinks().length" class="links space-y-6">
<div v-if="filteredLinks().length" class="links space-y-6">
<div v-for="item in filteredLinks()" id="links" :key="item.custom_id">
<div class="link">
<ElementChatbotLinkItem :item="item" :indexed="checkindexed(item.custom_id)" :httperror="checkHttpError(item.custom_id)" @close="closeForm" />
Expand Down Expand Up @@ -79,11 +82,11 @@ const loadLinks = async () => {
links.value = items.data;
indexedItems = await $fetch(`/api/brevia/index/${collection?.uuid}/documents_metadata?filter[type]=links`);
}
isLoading.value = false;
};
await loadLinks();
isLinkAddAllowed.value = checkAddAllowed(links);
setTimeout(() => (isLoading.value = false), 750);
const closeForm = async (e: boolean) => {
if (e) {
Expand Down
11 changes: 7 additions & 4 deletions components/Element/ChatbotQuestions.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<template>
<div class="flex flex-col space-y-10">
<div v-if="isLoading" class="flex flex-row mt-16 justify-center">
<ElementLoader :loader-dim="48" />
<span class="sr-only">loading...</span>
</div>
<div v-else class="flex flex-col space-y-10">
<!-- new -->
<div v-if="!addMode" class="flex flex-row justify-between">
<div>
Expand Down Expand Up @@ -35,8 +39,7 @@

<FormChatbotQuestion v-else @close="closeForm" />
<!-- existing -->
<div v-if="isLoading" class="-my-6 ellipsis-loading text-sky-700"><span class="sr-only">loading...</span></div>
<div v-else-if="questions?.length" class="questions space-y-6">
<div v-if="questions?.length" class="questions space-y-6">
<div v-for="item in questions" id="questions" :key="item.id">
<div v-if="showThis(item)" class="question">
<ElementChatbotQuestionItem :item="item" :search-term="searchTerm(searchInput)" @close="closeForm" />
Expand Down Expand Up @@ -68,10 +71,10 @@ const loadQuestions = async () => {
const endpoint = `${endpointBase}${addPath}?${query}`;
const items = await useApiGetAll(endpoint);
questions.value = items.data;
isLoading.value = false;
};
await loadQuestions();
isQuestionAddAllowed.value = checkAddAllowed(questions);
setTimeout(() => (isLoading.value = false), 750);
const searchTerm = (input: string) => {
if (input.trim().length > MIN_SEARCH_LENGTH) return input;
Expand Down
17 changes: 17 additions & 0 deletions components/Element/Loader.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" :width="loaderDim" :height="loaderDim" viewBox="0 0 24 24" class="animate-spin">
<g fill="#0284c7">
<path
fill-rule="evenodd"
d="M12 19a7 7 0 1 0 0-14a7 7 0 0 0 0 14m0 3c5.523 0 10-4.477 10-10S17.523 2 12 2S2 6.477 2 12s4.477 10 10 10"
clip-rule="evenodd"
opacity=".1"
/>
<path fill="112233" d="M2 12C2 6.477 6.477 2 12 2v3a7 7 0 0 0-7 7z" />
</g>
</svg>
</template>

<script setup lang="ts">
defineProps({ loaderDim: { type: Number, default: 24 } });
</script>
21 changes: 3 additions & 18 deletions pages/chatbot/history-[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,7 @@
</div>
<div>
<div v-if="loadingChats" class="flex flex-row justify-center">
<svg
aria-hidden="true"
class="w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
<ElementLoader :loader-dim="64" class="mt-16" />
<span class="sr-only">Loading...</span>
</div>
<div v-else-if="dialog.length">
Expand Down Expand Up @@ -287,10 +272,10 @@ const loadChat = async (id: any) => {
loadedDialog.push(formatDialogItem('ASSISTANT', data.data[i].answer, data.data[i].user_evaluation, data.data[i].user_feedback, data.data[i].uuid));
}
dialog.value = loadedDialog;
loadingChats.value = false;
setTimeout(() => (loadingChats.value = false), 250);
} catch (error) {
console.error(error);
loadingChats.value = false;
setTimeout(() => (loadingChats.value = false), 250);
}
};
Expand Down
21 changes: 14 additions & 7 deletions pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<template>
<main class="flex flex-col justify-stretch">
<DashboardMenu
v-if="statesStore.menu.length"
:class="{ 'opacity-70 pointer-events-none select-none': modalStore.isLoadingPage }"
:menu="statesStore.menu"
:add-enabled="isAddEnabled"
/>
<div v-if="isLoading" class="mx-auto mt-16">
<ElementLoader :loader-dim="82" />
</div>
<div v-else>
<DashboardMenu
v-if="statesStore.menu.length"
:class="{ 'opacity-70 pointer-events-none select-none': modalStore.isLoadingPage }"
:menu="statesStore.menu"
:add-enabled="isAddEnabled"
/>

<DashboardWelcome v-else-if="statesStore.isLogged()" :user="user" :add-enabled="isAddEnabled" />
<DashboardWelcome v-else-if="statesStore.isLogged()" :user="user" :add-enabled="isAddEnabled" />
</div>
</main>
</template>

Expand All @@ -16,6 +21,7 @@ const config = useRuntimeConfig();
useHead({ title: config.public.appName });
const modalStore = useModalStore();
const statesStore = useStatesStore();
const isLoading = ref(true);
const isAddEnabled = computed(() => {
if (config.public.maxUserChatbots === '') {
Expand All @@ -29,6 +35,7 @@ const isAddEnabled = computed(() => {
const integration = useIntegration();
const { data: menu, status } = await useFetch(`/api/${integration}/user_menu`);
statesStore.menu = buildUserMenu(menu.value);
setTimeout(() => (isLoading.value = false), 250);
watch(status, (value) => {
modalStore.isLoadingPage = value === 'pending';
Expand Down

0 comments on commit 98c0a15

Please sign in to comment.