perf(App): Display loading when fetching initial login status (#1793)

This commit is contained in:
Rémi Marseault 2024-07-19 07:26:46 -05:00 committed by GitHub
parent 5b9b2e0626
commit 1599b0f5e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 2 deletions

View file

@ -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 = () => {

View file

@ -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"

View file

@ -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) {