import { asError } from '@/utils/errorTypes';
import React from 'react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { AppRouter } from '@/routes';
import { setUnauthorizedHandler } from '@/api/client';
import { useAuthStore } from '@/store/authStore';
import { useThemeStore } from '@/store/themeStore';
import { ErrorBoundary } from '@/components/common/ErrorBoundary';
import { useToast } from '@/components/ui/Toast';
import { useOnlineStatus } from '@/hooks/useOnlineStatus';
function QueryClientWrapper({ children }: { children: React.ReactNode }) {
const toast = useToast();
const [queryClient] = React.useState(() => new QueryClient({
defaultOptions: {
queries: {
retry: 1,
staleTime: 5 * 60 * 1000,
refetchOnWindowFocus: false,
},
mutations: {
retry: 0,
onError: (error: unknown) => { const errObj = asError(error);
// Don't show toast for 401 (handled by auth)
if (errObj?.status === 401) return;
const msg = errObj?.detail || errObj?.message || 'Ein Fehler ist aufgetreten';
toast.error(msg);
},
},
},
}));
return (