diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index c718f3f8..22d8894c 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,9 +1,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query' -import { createBrowserRouter, RouterProvider, Outlet, useNavigate, useLocation, useNavigation } from 'react-router-dom' +import { createBrowserRouter, RouterProvider, Outlet, useNavigate, useLocation } from 'react-router-dom' import { useEffect, useRef, useCallback } from 'react' -import { AppLoadingSkeleton } from '@/components/ui/AppLoadingSkeleton' -import { RouteErrorBoundary } from '@/components/ui/RouteErrorBoundary' import { Toaster } from 'sonner' import { Repos } from './pages/Repos' import { RepoDetail } from './pages/RepoDetail' @@ -87,7 +85,6 @@ function PermissionDialogWrapper() { function AppShell() { const navigate = useNavigate() const location = useLocation() - const navigation = useNavigation() const rootRef = useRef(null) const { openSheet } = useMobileTabBar() useTheme() @@ -158,10 +155,6 @@ function AppShell() { return () => channel.close() }, [navigate]) - if (navigation.state === 'loading') { - return - } - return ( @@ -194,8 +187,6 @@ function AppShell() { const router = createBrowserRouter([ { element: , - errorElement: , - HydrateFallback: AppLoadingSkeleton, children: [ { path: '/login', diff --git a/frontend/src/components/ui/AppLoadingSkeleton.tsx b/frontend/src/components/ui/AppLoadingSkeleton.tsx deleted file mode 100644 index f73ab21b..00000000 --- a/frontend/src/components/ui/AppLoadingSkeleton.tsx +++ /dev/null @@ -1,63 +0,0 @@ -function SkeletonBlock({ className }: { className?: string }) { - return
-} - -function DesktopSidebarSkeleton() { - return ( -
- - {Array.from({ length: 6 }).map((_, i) => ( -
- - -
- ))} -
- - -
-
- ) -} - -function MobileTabBarSkeleton() { - return ( -
- {Array.from({ length: 4 }).map((_, i) => ( -
- - -
- ))} -
- ) -} - -function ContentSkeleton() { - return ( -
- -
- {Array.from({ length: 6 }).map((_, i) => ( -
-
- - -
- -
- ))} -
-
- ) -} - -export function AppLoadingSkeleton() { - return ( -
- - - -
- ) -} diff --git a/frontend/src/components/ui/RouteErrorBoundary.tsx b/frontend/src/components/ui/RouteErrorBoundary.tsx deleted file mode 100644 index fb0c603f..00000000 --- a/frontend/src/components/ui/RouteErrorBoundary.tsx +++ /dev/null @@ -1,81 +0,0 @@ -import { useRouteError, useNavigate, isRouteErrorResponse } from 'react-router-dom' -import { useEffect, useState } from 'react' -import { AppLoadingSkeleton } from '@/components/ui/AppLoadingSkeleton' -import { AlertTriangle, RefreshCw, WifiOff } from 'lucide-react' -import { Button } from '@/components/ui/button' - -function isNetworkError(error: unknown): boolean { - if (error instanceof TypeError && error.message === 'Failed to fetch') return true - if (error instanceof TypeError && error.message.includes('NetworkError')) return true - if (error instanceof TypeError && error.message.includes('network')) return true - return false -} - -export function RouteErrorBoundary() { - const error = useRouteError() - const navigate = useNavigate() - const [reconnecting, setReconnecting] = useState(false) - const [online, setOnline] = useState(navigator.onLine) - - useEffect(() => { - const handleOnline = () => setOnline(true) - const handleOffline = () => setOnline(false) - window.addEventListener('online', handleOnline) - window.addEventListener('offline', handleOffline) - return () => { - window.removeEventListener('online', handleOnline) - window.removeEventListener('offline', handleOffline) - } - }, []) - - useEffect(() => { - if (online && isNetworkError(error)) { - setReconnecting(true) - const timer = setTimeout(() => { - navigate(0) - }, 800) - return () => clearTimeout(timer) - } - }, [online, error, navigate]) - - if (isNetworkError(error)) { - if (reconnecting) return - - return ( -
- -
- -
-

No connection

-

Waiting to reconnect…

-
- -
-
- ) - } - - const message = isRouteErrorResponse(error) - ? `${error.status} ${error.statusText}` - : error instanceof Error - ? error.message - : 'An unexpected error occurred' - - return ( -
- -
-

Something went wrong

-

{message}

-
- -
- ) -} diff --git a/frontend/src/lib/auth-loaders.ts b/frontend/src/lib/auth-loaders.ts index 2270d786..cce1af14 100644 --- a/frontend/src/lib/auth-loaders.ts +++ b/frontend/src/lib/auth-loaders.ts @@ -1,17 +1,6 @@ import { redirect } from 'react-router-dom' import { getSession } from './auth-client' -function isNetworkError(error: unknown): boolean { - return error instanceof TypeError && (error.message === 'Failed to fetch' || error.message.includes('network')) -} - -const defaultAuthConfig: AuthConfig = { - enabledProviders: ['credentials'], - registrationEnabled: true, - isFirstUser: false, - adminConfigured: false, -} - export interface AuthConfig { enabledProviders: string[] registrationEnabled: boolean @@ -38,84 +27,66 @@ async function fetchAuthConfig(): Promise { } export async function loginLoader() { - try { - const [config, session] = await Promise.all([ - fetchAuthConfig(), - getSession(), - ]) + const [config, session] = await Promise.all([ + fetchAuthConfig(), + getSession(), + ]) - if (session.data?.user) { - return redirect('/') - } - - if (config.isFirstUser && !config.adminConfigured) { - return redirect('/setup') - } - - return { config } - } catch (error) { - if (isNetworkError(error)) return { config: defaultAuthConfig } - throw error + if (session.data?.user) { + return redirect('/') } + + if (config.isFirstUser && !config.adminConfigured) { + return redirect('/setup') + } + + return { config } } export async function setupLoader() { - try { - const [config, session] = await Promise.all([ - fetchAuthConfig(), - getSession(), - ]) + const [config, session] = await Promise.all([ + fetchAuthConfig(), + getSession(), + ]) - if (session.data?.user) { - return redirect('/') - } - - if (!config.isFirstUser || config.adminConfigured) { - return redirect('/login') - } - - return { config } - } catch (error) { - if (isNetworkError(error)) return { config: defaultAuthConfig } - throw error + if (session.data?.user) { + return redirect('/') } + + if (!config.isFirstUser || config.adminConfigured) { + return redirect('/login') + } + + return { config } } export async function registerLoader() { - try { - const [config, session] = await Promise.all([ - fetchAuthConfig(), - getSession(), - ]) + const [config, session] = await Promise.all([ + fetchAuthConfig(), + getSession(), + ]) - if (session.data?.user) { - return redirect('/') - } - - if (!config.registrationEnabled) { - return redirect('/login') - } - - if (config.isFirstUser && !config.adminConfigured) { - return redirect('/setup') - } - - return { config } - } catch (error) { - if (isNetworkError(error)) return { config: defaultAuthConfig } - throw error + if (session.data?.user) { + return redirect('/') } + + if (!config.registrationEnabled) { + return redirect('/login') + } + + if (config.isFirstUser && !config.adminConfigured) { + return redirect('/setup') + } + + return { config } } export async function protectedLoader() { - try { - const session = await getSession() - if (!session.data?.user) { - return redirect('/login') - } - return null - } catch (error) { - if (isNetworkError(error)) return null - throw error + const session = await getSession() + + if (!session.data?.user) { + return redirect('/login') } + + return null }