mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
fix: waiting modal flickering when quick response or error
This commit is contained in:
parent
3e877c1380
commit
66f0ed2370
4 changed files with 26 additions and 7 deletions
|
@ -7,7 +7,11 @@ import {
|
||||||
} from '@/composables/useRequests'
|
} from '@/composables/useRequests'
|
||||||
import { useSettings } from '@/composables/useSettings'
|
import { useSettings } from '@/composables/useSettings'
|
||||||
import type { Obj } from '@/types/commons'
|
import type { Obj } from '@/types/commons'
|
||||||
import { APIUnauthorizedError, type APIError } from './errors'
|
import {
|
||||||
|
APIBadRequestError,
|
||||||
|
APIUnauthorizedError,
|
||||||
|
type APIError,
|
||||||
|
} from './errors'
|
||||||
import { getError, getResponseData, openWebSocket } from './handlers'
|
import { getError, getResponseData, openWebSocket } from './handlers'
|
||||||
|
|
||||||
export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE'
|
export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE'
|
||||||
|
@ -143,8 +147,13 @@ export default {
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await getResponseData<string | APIErrorData>(response)
|
const errorData = await getResponseData<string | APIErrorData>(response)
|
||||||
endRequest({ request, success: false })
|
const err = getError(request, response, errorData)
|
||||||
throw getError(request, response, errorData)
|
endRequest({
|
||||||
|
request,
|
||||||
|
success: false,
|
||||||
|
isFormError: err instanceof APIBadRequestError,
|
||||||
|
})
|
||||||
|
throw err
|
||||||
}
|
}
|
||||||
|
|
||||||
const responseData = await getResponseData<T>(response)
|
const responseData = await getResponseData<T>(response)
|
||||||
|
|
|
@ -30,6 +30,7 @@ defineSlots<{
|
||||||
no-close-on-backdrop
|
no-close-on-backdrop
|
||||||
no-close-on-esc
|
no-close-on-esc
|
||||||
:hide-footer="hideFooter"
|
:hide-footer="hideFooter"
|
||||||
|
no-fade
|
||||||
>
|
>
|
||||||
<template #header>
|
<template #header>
|
||||||
<QueryHeader type="overlay" :request="request" tabindex="0" />
|
<QueryHeader type="overlay" :request="request" tabindex="0" />
|
||||||
|
|
|
@ -26,7 +26,7 @@ const progress = computed(() => {
|
||||||
<template>
|
<template>
|
||||||
<ModalOverlay :request="request">
|
<ModalOverlay :request="request">
|
||||||
<h5
|
<h5
|
||||||
v-t="messages || progress ? 'api.processing' : 'api.waiting'"
|
v-t="messages || progress ? 'api.processing' : 'api_waiting'"
|
||||||
class="text-center mt-4"
|
class="text-center mt-4"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ export type APIRequest = {
|
||||||
err?: APIError
|
err?: APIError
|
||||||
action?: APIActionProps
|
action?: APIActionProps
|
||||||
showModal?: boolean
|
showModal?: boolean
|
||||||
|
showModalTimeout?: number
|
||||||
}
|
}
|
||||||
type APIActionProps = {
|
type APIActionProps = {
|
||||||
messages: RequestMessage[]
|
messages: RequestMessage[]
|
||||||
|
@ -107,12 +108,12 @@ export const useRequests = createGlobalState(() => {
|
||||||
const r = requests.value[requests.value.length - 1]!
|
const r = requests.value[requests.value.length - 1]!
|
||||||
|
|
||||||
if (showModal) {
|
if (showModal) {
|
||||||
setTimeout(() => {
|
request.showModalTimeout = setTimeout(() => {
|
||||||
// Display the waiting modal only if the request takes some time.
|
// Display the waiting modal only if the request takes some time.
|
||||||
if (r.status === 'pending') {
|
if (r.status === 'pending') {
|
||||||
r.showModal = true
|
r.showModal = true
|
||||||
}
|
}
|
||||||
}, 300)
|
}, 300) as unknown as number
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
@ -121,12 +122,14 @@ export const useRequests = createGlobalState(() => {
|
||||||
function endRequest({
|
function endRequest({
|
||||||
request,
|
request,
|
||||||
success,
|
success,
|
||||||
|
isFormError = false,
|
||||||
}: {
|
}: {
|
||||||
request: APIRequest
|
request: APIRequest
|
||||||
success: boolean
|
success: boolean
|
||||||
|
isFormError?: boolean
|
||||||
}) {
|
}) {
|
||||||
let status: RequestStatus = success ? 'success' : 'error'
|
let status: RequestStatus = success ? 'success' : 'error'
|
||||||
let hideModal = success
|
let hideModal = success || isFormError
|
||||||
|
|
||||||
if (success && request.action) {
|
if (success && request.action) {
|
||||||
const { warnings, errors, messages } = request.action
|
const { warnings, errors, messages } = request.action
|
||||||
|
@ -137,6 +140,12 @@ export const useRequests = createGlobalState(() => {
|
||||||
if (errors || warnings) status = 'warning'
|
if (errors || warnings) status = 'warning'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request.showModalTimeout) {
|
||||||
|
// Clear the timeout to avoid delayed modal to show up
|
||||||
|
clearTimeout(request.showModalTimeout)
|
||||||
|
delete request.showModalTimeout
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
request.status = status
|
request.status = status
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue