source: frontend/src/App.tsx@ 765e166

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

add client side form for publishing new music with mock data and api calls

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