-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14c5595
commit c57c2e0
Showing
1 changed file
with
101 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,114 @@ | ||
import React from "react"; | ||
import { | ||
Navbar, | ||
Collapse, | ||
Typography, | ||
IconButton, | ||
Navbar, | ||
Collapse, | ||
Typography, | ||
IconButton, | ||
} from "@material-tailwind/react"; | ||
import { Bars3Icon, XMarkIcon } from "@heroicons/react/24/outline"; | ||
import { useRecoilValue } from 'recoil'; | ||
import { userloggedin } from '../atom/userAtom' | ||
|
||
import { useRecoilValue } from "recoil"; | ||
import { userloggedin } from "../atom/userAtom"; | ||
|
||
function NavList() { | ||
const loggedUser = useRecoilValue(userloggedin); | ||
return ( | ||
loggedUser == 'anonymous-not-loggedin' ? ( | ||
|
||
< ul className="my-2 flex flex-col gap-2 lg:mb-0 lg:mt-0 lg:flex-row lg:items-center lg:gap-6" > | ||
<Typography | ||
as="li" | ||
variant="small" | ||
color="blue-gray" | ||
className="p-1 font-medium" | ||
> | ||
<a href="http://localhost:5173/fetchusers" className="flex items-center hover:text-blue-500 transition-colors"> | ||
Allusers | ||
</a> | ||
</Typography> | ||
<Typography | ||
as="li" | ||
variant="small" | ||
color="blue-gray" | ||
className="p-1 font-medium" | ||
> | ||
<a href="http://localhost:5173/register" className="flex items-center hover:text-blue-500 transition-colors"> | ||
Register | ||
</a> | ||
</Typography> | ||
<Typography | ||
as="li" | ||
variant="small" | ||
color="blue-gray" | ||
className="p-1 font-medium" | ||
> | ||
<a href="http://localhost:5173/login" className="flex items-center hover:text-blue-500 transition-colors"> | ||
Login | ||
</a> | ||
</Typography> | ||
|
||
</ul > | ||
) : ( | ||
<Typography | ||
as="li" | ||
variant="small" | ||
color="blue-gray" | ||
className="p-1 font-medium" | ||
> | ||
<p>User logged in as : {loggedUser}</p> | ||
</Typography>) | ||
); | ||
const loggedUser = useRecoilValue(userloggedin); | ||
return loggedUser == "anonymous-not-loggedin" ? ( | ||
<ul className="my-2 flex flex-col gap-2 lg:mb-0 lg:mt-0 lg:flex-row lg:items-center lg:gap-6"> | ||
<Typography | ||
as="li" | ||
variant="small" | ||
color="blue-gray" | ||
className="p-1 font-medium" | ||
> | ||
<a | ||
href="/fetchusers" | ||
className="flex items-center hover:text-blue-500 transition-colors" | ||
> | ||
Allusers | ||
</a> | ||
</Typography> | ||
<Typography | ||
as="li" | ||
variant="small" | ||
color="blue-gray" | ||
className="p-1 font-medium" | ||
> | ||
<a | ||
href="/register" | ||
className="flex items-center hover:text-blue-500 transition-colors" | ||
> | ||
Register | ||
</a> | ||
</Typography> | ||
<Typography | ||
as="li" | ||
variant="small" | ||
color="blue-gray" | ||
className="p-1 font-medium" | ||
> | ||
<a | ||
href="/login" | ||
className="flex items-center hover:text-blue-500 transition-colors" | ||
> | ||
Login | ||
</a> | ||
</Typography> | ||
</ul> | ||
) : ( | ||
<Typography | ||
as="li" | ||
variant="small" | ||
color="blue-gray" | ||
className="p-1 font-medium" | ||
> | ||
<p>User logged in as : {loggedUser}</p> | ||
</Typography> | ||
); | ||
} | ||
|
||
export function NavbarSimple() { | ||
const [openNav, setOpenNav] = React.useState(false); | ||
const [openNav, setOpenNav] = React.useState(false); | ||
|
||
const handleWindowResize = () => | ||
window.innerWidth >= 960 && setOpenNav(false); | ||
const handleWindowResize = () => | ||
window.innerWidth >= 960 && setOpenNav(false); | ||
|
||
React.useEffect(() => { | ||
window.addEventListener("resize", handleWindowResize); | ||
React.useEffect(() => { | ||
window.addEventListener("resize", handleWindowResize); | ||
|
||
return () => { | ||
window.removeEventListener("resize", handleWindowResize); | ||
}; | ||
}, []); | ||
return () => { | ||
window.removeEventListener("resize", handleWindowResize); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<Navbar className="mx-auto max-w-screen-xl px-6 py-3"> | ||
<div className="flex items-center justify-between text-blue-gray-900"> | ||
<Typography | ||
as="a" | ||
href="#" | ||
variant="h6" | ||
className="mr-4 cursor-pointer py-1.5" | ||
> | ||
Chat Room | ||
</Typography> | ||
<div className="hidden lg:block"> | ||
<NavList /> | ||
</div> | ||
<IconButton | ||
variant="text" | ||
className="ml-auto h-6 w-6 text-inherit hover:bg-transparent focus:bg-transparent active:bg-transparent lg:hidden" | ||
ripple={false} | ||
onClick={() => setOpenNav(!openNav)} | ||
> | ||
{openNav ? ( | ||
<XMarkIcon className="h-6 w-6" strokeWidth={2} /> | ||
) : ( | ||
<Bars3Icon className="h-6 w-6" strokeWidth={2} /> | ||
)} | ||
</IconButton> | ||
</div> | ||
<Collapse open={openNav}> | ||
<NavList /> | ||
</Collapse> | ||
</Navbar> | ||
); | ||
} | ||
return ( | ||
<Navbar className="mx-auto max-w-screen-xl px-6 py-3"> | ||
<div className="flex items-center justify-between text-blue-gray-900"> | ||
<Typography | ||
as="a" | ||
href="#" | ||
variant="h6" | ||
className="mr-4 cursor-pointer py-1.5" | ||
> | ||
Chat Room | ||
</Typography> | ||
<div className="hidden lg:block"> | ||
<NavList /> | ||
</div> | ||
<IconButton | ||
variant="text" | ||
className="ml-auto h-6 w-6 text-inherit hover:bg-transparent focus:bg-transparent active:bg-transparent lg:hidden" | ||
ripple={false} | ||
onClick={() => setOpenNav(!openNav)} | ||
> | ||
{openNav ? ( | ||
<XMarkIcon className="h-6 w-6" strokeWidth={2} /> | ||
) : ( | ||
<Bars3Icon className="h-6 w-6" strokeWidth={2} /> | ||
)} | ||
</IconButton> | ||
</div> | ||
<Collapse open={openNav}> | ||
<NavList /> | ||
</Collapse> | ||
</Navbar> | ||
); | ||
} |