Skip to content

Commit

Permalink
navbar added
Browse files Browse the repository at this point in the history
  • Loading branch information
tester committed Oct 7, 2024
1 parent 8556c52 commit ba5515f
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 31 deletions.
48 changes: 48 additions & 0 deletions frontend/src/components/MainNavbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { useEffect, useState } from 'react';
import { Outlet, useNavigate } from 'react-router-dom';
import { useLocation } from 'react-router-dom';
import { Link } from 'react-router-dom';
const Navbar = () => {
const navigate = useNavigate();
const location = useLocation();
useEffect(() => {
console.log("here");
if (location.pathname === '/') navigate("/homepage");
}, [location]);
return (
<div>
<nav className="flex bg-gray-800 p-4">
<div className="container mx-auto flex justify-between items-center">
<div className="text-white text-xl font-bold">
<Link to="/">MyApp</Link>
</div>
<div className="hidden md:flex space-x-4">
<Link to="/homepage" className="text-gray-300 hover:text-white m-3">
Home
</Link>
<Link to="/login" className="text-gray-300 hover:text-white">
Login
</Link>
<Link to="/posts" className="text-gray-300 hover:text-white">
post
</Link>
<Link to="/room" className="text-gray-300 hover:text-white">
room
</Link>
</div>
<div className="md:hidden">
<button className="text-gray-300 hover:text-white focus:outline-none">
{/* Icon for mobile menu (e.g. hamburger icon) */}
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16m-7 6h7" />
</svg>
</button>
</div>
</div>
</nav>
<Outlet></Outlet>
</div>
);
};

export default Navbar;
9 changes: 9 additions & 0 deletions frontend/src/components/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react"
export default function Loader(){
return(
<div
className="w-12 h-12 rounded-full animate-spin border-y-8 border-solid border-green-500 border-t-transparent shadow-md"
>
</div>
)
}
71 changes: 40 additions & 31 deletions frontend/src/components/routes/mainroute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import HomePage from "../../pages/HomePage";
import Register from "../Register";
import SinglePost from "../../components/SinglePost";
import LoginPage from "../Login";
import Navbar from "../MainNavbar";
import Loader from "../loading";
const Test = () => {
const [userId, setUserId] = useState("");
const [roomId, setRoomId] = useState("");
Expand Down Expand Up @@ -47,45 +49,52 @@ const Test = () => {
const Mainrouter = createBrowserRouter([
{
path: "/",
element: <HomePage />,
},
{
path: "/posts",
element: <Posts />,
},
{
path: "/posts/:id",
element: <SinglePost />,
},
{
path: "/login",
element: <LoginPage />,
},
{
path: "/signup",
element: <Register />,
},
{
path: "/room",
element: <Test />,
children: [
element: <Navbar />,
children:[
{
path: "/room",
element: <Mainbuttons />,
index: true,
path:"homepage",
element:<HomePage></HomePage>
},
{
path: "posts",
element: <Posts />,
},
{
path: "/room/createroom",
element: <Createroom />,
path: "posts/:id",
element: <SinglePost />,
},
{
path: "/room/joinroom",
element: <Joinroom />,
path: "login",
element: <LoginPage />,
},
{
path: "/room/chatting",
element: <Chatroom />,
path: "/signup",
element: <Register />,
},
{
path: "/room",
element: <Test />,
children: [
{
path: "/room",
element: <Mainbuttons />,
index: true,
},
{
path: "/room/createroom",
element: <Createroom />,
},
{
path: "/room/joinroom",
element: <Joinroom />,
},
{
path: "/room/chatting",
element: <Chatroom />,
},
],
},

],
},
]);
Expand Down

0 comments on commit ba5515f

Please sign in to comment.