import type { ReactNode } from 'react' import { ApiError } from '@/api/fetcher' import { Skeleton } from '@/components/ui/skeleton' import { Button } from '@/components/ui/button' import { m } from '@/paraglide/messages' interface QueryStateProps { isLoading: boolean error: unknown refetch?: () => void children: ReactNode } /** Uniform loading/error wrapper for a query-backed view. */ export function QueryState({ isLoading, error, refetch, children }: QueryStateProps) { if (isLoading) { return (
) } if (error) { const unauthorized = error instanceof ApiError && error.status === 401 return (

{unauthorized ? m.common_unauthorized() : m.common_error()}

{refetch && !unauthorized && ( )}
) } return <>{children} }