source: frontend/src/App.tsx@ 8a47b30

main
Last change on this file since 8a47b30 was 8a47b30, checked in by Filip Gavrilovski <filipgavrilovski28@…>, 5 months ago

add endpoint for fetching aggregated song details and song detail view

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[dc30259]1import { useEffect, useState } from "react";
2import {
3 createBrowserRouter,
4 Outlet,
5 RouterProvider,
6 useLocation,
7} from "react-router-dom";
[b70fbeb]8import { ToastContainer } from "react-toastify";
9import "react-toastify/dist/ReactToastify.css";
[dc30259]10import LoadingSpinner from "./components/LoadingSpinner";
[cb4a1da]11import Sidebar from "./components/Sidebar";
[5938bc9]12import { useAuth } from "./context/authContext";
[4e5cf92]13import AllUsers from "./pages/AllUsers";
14import LandingPage from "./pages/LandingPage";
15import Login from "./pages/Login";
[cb4a1da]16import MusicalCollection from "./pages/MusicalCollection";
[4e5cf92]17import Nav from "./pages/Nav";
18import Register from "./pages/Register";
[8a47b30]19import SongDetail from "./pages/SongDetail";
[2730163]20import UserDetail from "./pages/UserDetail";
[15ec67f]21
[5938bc9]22const MainLayout = () => {
23 const { user } = useAuth();
[dc30259]24 const location = useLocation();
25 // show sidebar only if user is logged in and is on the landing page
26 const isLandingPage = location.pathname === "/";
27 const [isSidebarOpen, setIsSidebarOpen] = useState(!!user && isLandingPage);
28
29 // Open sidebar when user logs in and navigates to landing page
30 useEffect(() => {
31 if (user && isLandingPage) {
32 setIsSidebarOpen(true);
33 }
34 }, [user, isLandingPage]);
[cb4a1da]35
36 return (
37 <div className="flex flex-col min-h-screen bg-[#121212]">
38 <Nav
39 isSidebarOpen={isSidebarOpen}
40 onToggleSidebar={() => setIsSidebarOpen(!isSidebarOpen)}
41 />
42 <Sidebar isOpen={isSidebarOpen} onClose={() => setIsSidebarOpen(false)} />
43 <ToastContainer
44 position="top-right"
45 autoClose={2000}
46 hideProgressBar={false}
47 newestOnTop={false}
48 closeOnClick
49 rtl={false}
50 pauseOnFocusLoss
51 draggable
52 pauseOnHover
53 theme="light"
54 />
55 <main
56 className={`grow transition-all duration-300 pt-20 ${
57 isSidebarOpen ? "ml-64" : "ml-0"
58 }`}
59 >
60 <Outlet />
61 </main>
62 </div>
63 );
[0c86e77]64};
65
[5938bc9]66const Layout = () => {
67 const { isAuthLoading } = useAuth();
68
69 if (isAuthLoading) {
[dc30259]70 return <LoadingSpinner />;
[5938bc9]71 }
72
73 return <MainLayout />;
74};
75
[0c86e77]76const router = createBrowserRouter([
[cb4a1da]77 {
78 path: "",
79 element: <Layout />,
80 children: [
81 {
82 path: "/",
83 element: <LandingPage />,
84 },
85 {
86 path: "/login",
87 element: <Login />,
88 },
89 {
90 path: "/users",
91 element: <AllUsers />,
92 },
93 {
94 path: "/users/:username",
95 element: <UserDetail />,
96 },
97 {
98 path: "/register",
99 element: <Register />,
100 },
[8a47b30]101 {
102 path: "/songs/:id",
103 element: <SongDetail />,
104 },
[cb4a1da]105 {
106 path: "/collection/:type/:id",
107 element: <MusicalCollection />,
108 },
[ebdd3d4]109 {
110 path: "/me",
111 element: <UserDetail />,
112 },
[cb4a1da]113 ],
114 },
[0c86e77]115]);
116
117function App() {
[cb4a1da]118 return <RouterProvider router={router} />;
[15ec67f]119}
120
121export default App;
Note: See TracBrowser for help on using the repository browser.