| 1 | import { useState } from "react";
|
|---|
| 2 | import { createBrowserRouter, Outlet, RouterProvider } from "react-router-dom";
|
|---|
| 3 | import { ToastContainer } from "react-toastify";
|
|---|
| 4 | import "react-toastify/dist/ReactToastify.css";
|
|---|
| 5 | import Sidebar from "./components/Sidebar";
|
|---|
| 6 | import { useAuth } from "./context/authContext";
|
|---|
| 7 | import AllUsers from "./pages/AllUsers";
|
|---|
| 8 | import LandingPage from "./pages/LandingPage";
|
|---|
| 9 | import Login from "./pages/Login";
|
|---|
| 10 | import MusicalCollection from "./pages/MusicalCollection";
|
|---|
| 11 | import Nav from "./pages/Nav";
|
|---|
| 12 | import Register from "./pages/Register";
|
|---|
| 13 | import UserDetail from "./pages/UserDetail";
|
|---|
| 14 |
|
|---|
| 15 | const MainLayout = () => {
|
|---|
| 16 | const { user } = useAuth();
|
|---|
| 17 | const [isSidebarOpen, setIsSidebarOpen] = useState(!!user);
|
|---|
| 18 |
|
|---|
| 19 | return (
|
|---|
| 20 | <div className="flex flex-col min-h-screen bg-[#121212]">
|
|---|
| 21 | <Nav
|
|---|
| 22 | isSidebarOpen={isSidebarOpen}
|
|---|
| 23 | onToggleSidebar={() => setIsSidebarOpen(!isSidebarOpen)}
|
|---|
| 24 | />
|
|---|
| 25 | <Sidebar isOpen={isSidebarOpen} onClose={() => setIsSidebarOpen(false)} />
|
|---|
| 26 | <ToastContainer
|
|---|
| 27 | position="top-right"
|
|---|
| 28 | autoClose={2000}
|
|---|
| 29 | hideProgressBar={false}
|
|---|
| 30 | newestOnTop={false}
|
|---|
| 31 | closeOnClick
|
|---|
| 32 | rtl={false}
|
|---|
| 33 | pauseOnFocusLoss
|
|---|
| 34 | draggable
|
|---|
| 35 | pauseOnHover
|
|---|
| 36 | theme="light"
|
|---|
| 37 | />
|
|---|
| 38 | <main
|
|---|
| 39 | className={`grow transition-all duration-300 pt-20 ${
|
|---|
| 40 | isSidebarOpen ? "ml-64" : "ml-0"
|
|---|
| 41 | }`}
|
|---|
| 42 | >
|
|---|
| 43 | <Outlet />
|
|---|
| 44 | </main>
|
|---|
| 45 | </div>
|
|---|
| 46 | );
|
|---|
| 47 | };
|
|---|
| 48 |
|
|---|
| 49 | const Layout = () => {
|
|---|
| 50 | const { isAuthLoading } = useAuth();
|
|---|
| 51 |
|
|---|
| 52 | if (isAuthLoading) {
|
|---|
| 53 | return (
|
|---|
| 54 | <div className="flex h-screen items-center justify-center bg-[#121212]">
|
|---|
| 55 | <div className="w-12 h-12 border-4 border-white/10 border-t-[#1db954] rounded-full animate-spin"></div>
|
|---|
| 56 | </div>
|
|---|
| 57 | );
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | return <MainLayout />;
|
|---|
| 61 | };
|
|---|
| 62 |
|
|---|
| 63 | const router = createBrowserRouter([
|
|---|
| 64 | {
|
|---|
| 65 | path: "",
|
|---|
| 66 | element: <Layout />,
|
|---|
| 67 | children: [
|
|---|
| 68 | {
|
|---|
| 69 | path: "/",
|
|---|
| 70 | element: <LandingPage />,
|
|---|
| 71 | },
|
|---|
| 72 | {
|
|---|
| 73 | path: "/login",
|
|---|
| 74 | element: <Login />,
|
|---|
| 75 | },
|
|---|
| 76 | {
|
|---|
| 77 | path: "/users",
|
|---|
| 78 | element: <AllUsers />,
|
|---|
| 79 | },
|
|---|
| 80 | {
|
|---|
| 81 | path: "/users/:username",
|
|---|
| 82 | element: <UserDetail />,
|
|---|
| 83 | },
|
|---|
| 84 | {
|
|---|
| 85 | path: "/register",
|
|---|
| 86 | element: <Register />,
|
|---|
| 87 | },
|
|---|
| 88 | {
|
|---|
| 89 | path: "/collection/:type/:id",
|
|---|
| 90 | element: <MusicalCollection />,
|
|---|
| 91 | },
|
|---|
| 92 | ],
|
|---|
| 93 | },
|
|---|
| 94 | ]);
|
|---|
| 95 |
|
|---|
| 96 | function App() {
|
|---|
| 97 | return <RouterProvider router={router} />;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | export default App;
|
|---|