mirror of
https://github.com/R0m1k3/podcastic.git
synced 2026-10-17 04:09:15 +02:00
86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
import './styles/globals.css';
|
|
import { authService } from './services/authService';
|
|
import Login from './pages/Login';
|
|
import Dashboard from './pages/Dashboard';
|
|
import Trending from './pages/Trending';
|
|
import AddPodcast from './pages/AddPodcast';
|
|
import Library from './pages/Library';
|
|
import Navigation from './components/Navigation';
|
|
|
|
const queryClient = new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
staleTime: 1000 * 60 * 5, // 5 minutes
|
|
gcTime: 1000 * 60 * 30, // 30 minutes (formerly cacheTime)
|
|
},
|
|
},
|
|
});
|
|
|
|
// Protected Route Component
|
|
function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
|
const { accessToken } = authService.getTokens();
|
|
|
|
if (!accessToken) {
|
|
return <Navigate to="/login" replace />;
|
|
}
|
|
|
|
return (
|
|
<div className="flex bg-obsidian min-h-screen">
|
|
<Navigation />
|
|
<main className="flex-1 lg:ml-80 lg:mr-8 pb-32 pt-8 px-4 lg:px-0">
|
|
<div className="reveal">
|
|
{children}
|
|
</div>
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function App() {
|
|
return (
|
|
<QueryClientProvider client={queryClient}>
|
|
<BrowserRouter>
|
|
<Routes>
|
|
<Route path="/login" element={<Login />} />
|
|
<Route
|
|
path="/dashboard"
|
|
element={
|
|
<ProtectedRoute>
|
|
<Dashboard />
|
|
</ProtectedRoute>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/trending"
|
|
element={
|
|
<ProtectedRoute>
|
|
<Trending />
|
|
</ProtectedRoute>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/add"
|
|
element={
|
|
<ProtectedRoute>
|
|
<AddPodcast />
|
|
</ProtectedRoute>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/library"
|
|
element={
|
|
<ProtectedRoute>
|
|
<Library />
|
|
</ProtectedRoute>
|
|
}
|
|
/>
|
|
<Route path="/" element={<Navigate to="/dashboard" replace />} />
|
|
<Route path="*" element={<Navigate to="/dashboard" replace />} />
|
|
</Routes>
|
|
</BrowserRouter>
|
|
</QueryClientProvider>
|
|
);
|
|
}
|