This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts" generic="R, E">
|
||||
import type { UseQueryReturnType } from '@tanstack/vue-query'
|
||||
import { ROUTE_NAMES } from '@/constants/routes'
|
||||
|
||||
type Props = {
|
||||
query: UseQueryReturnType<R, E>
|
||||
@@ -7,6 +8,7 @@ type Props = {
|
||||
|
||||
const slots = defineSlots<{
|
||||
default?: (slotBindings: { data: R }) => void
|
||||
notFound?: (slotBindings: { error: E; reload: typeof refetch }) => void
|
||||
error?: (slotBindings: { error: E; reload: typeof refetch }) => void
|
||||
loading?: () => void
|
||||
}>()
|
||||
@@ -23,6 +25,28 @@ const { data, error, refetch, isSuccess, isError, isLoading } = query
|
||||
<ProgressSpinner styleClass="mt-4" />
|
||||
</div>
|
||||
</slot>
|
||||
|
||||
<slot
|
||||
v-else-if="
|
||||
isError &&
|
||||
error &&
|
||||
typeof error === 'object' &&
|
||||
'error' in error &&
|
||||
error.error === 'not_found'
|
||||
"
|
||||
name="notFound"
|
||||
:error="error!"
|
||||
:reload="refetch"
|
||||
>
|
||||
<template v-if="!slots.notFound">
|
||||
Страница не найдена<br />
|
||||
<RouterLink
|
||||
:to="{ name: ROUTE_NAMES.HOME }"
|
||||
class="underline text-blue-600 dark:text-blue-400"
|
||||
>Перейти на главную</RouterLink
|
||||
></template
|
||||
>
|
||||
</slot>
|
||||
<slot v-else-if="isError" name="error" :error="error!" :reload="refetch">
|
||||
<template v-if="!slots.error">
|
||||
Ошибка загрузки данных:
|
||||
|
||||
Reference in New Issue
Block a user