From 1599b0f5e776038e3943f2a29633be30fb8b37c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Marseault?= <22910497+Larsluph@users.noreply.github.com> Date: Fri, 19 Jul 2024 07:26:46 -0500 Subject: [PATCH] perf(App): Display loading when fetching initial login status (#1793) --- src/App.vue | 7 ++++++- src/locales/en.json | 1 + src/stores/app.ts | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/App.vue b/src/App.vue index 650a09fe..7eaf5a1d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -9,7 +9,10 @@ import { backend } from '@/services/backend' import { useAddTorrentStore, useAppStore, useDialogStore, useLogStore, useMaindataStore, usePreferenceStore, useTorrentStore, useVueTorrentStore } from '@/stores' import { storeToRefs } from 'pinia' import { onBeforeMount, watch, watchEffect } from 'vue' +import { useI18n } from 'vue-i18n' +import { toast } from 'vue3-toastify' +const { t } = useI18n() const addTorrentStore = useAddTorrentStore() const appStore = useAppStore() const dialogStore = useDialogStore() @@ -22,7 +25,9 @@ const vuetorrentStore = useVueTorrentStore() const { language, uiTitleCustom, uiTitleType, useBitSpeed } = storeToRefs(vuetorrentStore) const checkAuthentication = async () => { - await appStore.fetchAuthStatus() + const promise = appStore.fetchAuthStatus() + const timer = setTimeout(() => toast.promise(promise, { pending: t('login.pending')}), 1000) + promise.then(() => clearTimeout(timer)) } const blockContextMenu = () => { diff --git a/src/locales/en.json b/src/locales/en.json index 81c73859..e7c4b05b 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -474,6 +474,7 @@ "login": { "error": "Login failed!", "password": "Password", + "pending": "Checking current auth status...", "rules": { "password_required": "Password is required", "username_required": "Username is required" diff --git a/src/stores/app.ts b/src/stores/app.ts index 923341d7..515b987f 100644 --- a/src/stores/app.ts +++ b/src/stores/app.ts @@ -8,7 +8,9 @@ export const useAppStore = defineStore('app', () => { async function fetchAuthStatus() { const ver: string | false = await qbit.getVersion().catch(() => false) - await setAuthStatus(ver !== false, ver || undefined) + const auth_status = ver !== false + await setAuthStatus(auth_status, ver || undefined) + return auth_status } async function setAuthStatus(val: boolean, ver?: string) {