Guest User

Untitled

a guest
May 4th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.64 KB | None | 0 0
  1. import {
  2. Navbar as NextUINavbar,
  3. NavbarContent,
  4. NavbarMenu,
  5. NavbarMenuToggle,
  6. NavbarItem,
  7. NavbarMenuItem,
  8. } from "@nextui-org/navbar";
  9. import { Input } from "@nextui-org/react";
  10. import { Link } from "@nextui-org/link";
  11. import { siteConfig } from "@/config/site";
  12. import NextLink from "next/link";
  13. import clsx from "clsx";
  14. import { User } from "@nextui-org/react";
  15. import { getUser, logout } from "./../server/utils/auth";
  16. import { SearchIcon } from "@/components/icons";
  17. import { useState, useEffect } from "react";
  18. import { fetchDiscordInfo } from "../server/utils/data";
  19. import {
  20. Dropdown,
  21. DropdownTrigger,
  22. DropdownMenu,
  23. DropdownSection,
  24. DropdownItem,
  25. } from "@nextui-org/dropdown";
  26. import { useRouter } from "next/navigation";
  27.  
  28. import { useToast } from "@/components/ui/use-toast";
  29.  
  30. export const Navbar = () => {
  31. const router = useRouter();
  32. const { toast } = useToast();
  33. const [user, setUser] = useState(null);
  34. const [data, setData] = useState(null);
  35.  
  36. useEffect(() => {
  37. const fetchUser = async () => {
  38. const userData = await getUser();
  39. console.log(userData);
  40. const discordData = await fetchDiscordInfo();
  41. setUser(userData);
  42. //@ts-ignore
  43. setData(discordData);
  44. };
  45.  
  46. fetchUser();
  47. }, []);
  48.  
  49. const handleLogout = async () => {
  50. const res = await logout();
  51.  
  52. if (res === true) {
  53. router.push("/");
  54.  
  55. toast({
  56. variant: "default",
  57. title: "Successfully logged out!",
  58. });
  59. } else {
  60. toast({
  61. variant: "destructive",
  62. title: "Logout Failed",
  63. description: "Please try again later!",
  64. });
  65. }
  66. };
  67.  
  68. return (
  69. <NextUINavbar
  70. maxWidth="xl"
  71. className="bg-transparent blur-none backdrop-blur-none"
  72. >
  73. <NavbarContent className="flex justify-between items-center mx-4">
  74. <ul className="hidden lg:flex gap-16 uppercase justify-start center">
  75. {siteConfig.navItems.map((item) => (
  76. <NavbarItem key={item.href}>
  77. <NextLink
  78. className={`${clsx(
  79. "font-clean",
  80. "data-[active=true]:text-opacity-100 data-[active=true]:font-medium",
  81. "rounded-md p-2 transition-colors duration-800",
  82. "text-white", // Text color
  83. "text-opacity-60", // Text opacity
  84. "text-base", // Font size
  85. "font-semibold", // Font weight
  86. "uppercase", // Text transform
  87. "tracking-widest", // Letter spacing
  88. "hover:text-opacity-80"
  89. )}`}
  90. href={item.href}
  91. >
  92. {item.label}
  93. </NextLink>
  94. </NavbarItem>
  95. ))}
  96. </ul>
  97. <div className="flex items-center">
  98. <Input
  99. classNames={{
  100. base: "max-w-full h-10 w-52 mx-8",
  101. mainWrapper: "h-full",
  102. input: "text-small",
  103. inputWrapper:
  104. "h-full font-normal text-default-500 bg-default-400/20 dark:bg-default-500/20 bg-transparent",
  105. }}
  106. placeholder="SEARCH"
  107. size="md"
  108. startContent={
  109. <SearchIcon size={18} width={undefined} height={undefined} />
  110. }
  111. type="search"
  112. style={{
  113. fontWeight: "500",
  114. fontFamily: "Nunito Sans 7pt",
  115. }}
  116. />
  117.  
  118. {user ? (
  119. <Dropdown>
  120. <DropdownTrigger>
  121. <NavbarItem className="mx-16">
  122. <a className="cursor-pointer">
  123. <User
  124. isFocusable
  125. //@ts-ignore
  126. name={user.username}
  127. //@ts-ignore
  128. description={user.rank}
  129. avatarProps={{
  130. //@ts-ignore
  131. src: user.avatar,
  132. }}
  133. />
  134. </a>
  135. </NavbarItem>
  136. </DropdownTrigger>
  137. <DropdownMenu aria-label="Static Actions">
  138. <DropdownSection showDivider>
  139. <DropdownItem
  140. href={"/profile"}
  141. key="new"
  142. startContent={
  143. <svg
  144. className="shrink-0 w-6 aspect-square fill-sky-300"
  145. xmlns="http://www.w3.org/2000/svg"
  146. viewBox="0 0 640 512"
  147. >
  148. <path d="M224 256A128 128 0 1 0 224 0a128 128 0 1 0 0 256zm-45.7 48C79.8 304 0 383.8 0 482.3C0 498.7 13.3 512 29.7 512H418.3c16.4 0 29.7-13.3 29.7-29.7C448 383.8 368.2 304 269.7 304H178.3z" />
  149. </svg>
  150. }
  151. >
  152. My Profile
  153. </DropdownItem>
  154.  
  155. <DropdownItem
  156. href={"/settings"}
  157. key="new"
  158. startContent={
  159. <svg
  160. className="shrink-0 w-6 aspect-square fill-sky-300"
  161. xmlns="http://www.w3.org/2000/svg"
  162. viewBox="0 0 640 512"
  163. >
  164. <path d="M308.5 135.3c7.1-6.3 9.9-16.2 6.2-25c-2.3-5.3-4.8-10.5-7.6-15.5L304 89.4c-3-5-6.3-9.9-9.8-14.6c-5.7-7.6-15.7-10.1-24.7-7.1l-28.2 9.3c-10.7-8.8-23-16-36.2-20.9L199 27.1c-1.9-9.3-9.1-16.7-18.5-17.8C173.9 8.4 167.2 8 160.4 8h-.7c-6.8 0-13.5 .4-20.1 1.2c-9.4 1.1-16.6 8.6-18.5 17.8L115 56.1c-13.3 5-25.5 12.1-36.2 20.9L50.5 67.8c-9-3-19-.5-24.7 7.1c-3.5 4.7-6.8 9.6-9.9 14.6l-3 5.3c-2.8 5-5.3 10.2-7.6 15.6c-3.7 8.7-.9 18.6 6.2 25l22.2 19.8C32.6 161.9 32 168.9 32 176s.6 14.1 1.7 20.9L11.5 216.7c-7.1 6.3-9.9 16.2-6.2 25c2.3 5.3 4.8 10.5 7.6 15.6l3 5.2c3 5.1 6.3 9.9 9.9 14.6c5.7 7.6 15.7 10.1 24.7 7.1l28.2-9.3c10.7 8.8 23 16 36.2 20.9l6.1 29.1c1.9 9.3 9.1 16.7 18.5 17.8c6.7 .8 13.5 1.2 20.4 1.2s13.7-.4 20.4-1.2c9.4-1.1 16.6-8.6 18.5-17.8l6.1-29.1c13.3-5 25.5-12.1 36.2-20.9l28.2 9.3c9 3 19 .5 24.7-7.1c3.5-4.7 6.8-9.5 9.8-14.6l3.1-5.4c2.8-5 5.3-10.2 7.6-15.5c3.7-8.7 .9-18.6-6.2-25l-22.2-19.8c1.1-6.8 1.7-13.8 1.7-20.9s-.6-14.1-1.7-20.9l22.2-19.8zM112 176a48 48 0 1 1 96 0 48 48 0 1 1 -96 0zM504.7 500.5c6.3 7.1 16.2 9.9 25 6.2c5.3-2.3 10.5-4.8 15.5-7.6l5.4-3.1c5-3 9.9-6.3 14.6-9.8c7.6-5.7 10.1-15.7 7.1-24.7l-9.3-28.2c8.8-10.7 16-23 20.9-36.2l29.1-6.1c9.3-1.9 16.7-9.1 17.8-18.5c.8-6.7 1.2-13.5 1.2-20.4s-.4-13.7-1.2-20.4c-1.1-9.4-8.6-16.6-17.8-18.5L583.9 307c-5-13.3-12.1-25.5-20.9-36.2l9.3-28.2c3-9 .5-19-7.1-24.7c-4.7-3.5-9.6-6.8-14.6-9.9l-5.3-3c-5-2.8-10.2-5.3-15.6-7.6c-8.7-3.7-18.6-.9-25 6.2l-19.8 22.2c-6.8-1.1-13.8-1.7-20.9-1.7s-14.1 .6-20.9 1.7l-19.8-22.2c-6.3-7.1-16.2-9.9-25-6.2c-5.3 2.3-10.5 4.8-15.6 7.6l-5.2 3c-5.1 3-9.9 6.3-14.6 9.9c-7.6 5.7-10.1 15.7-7.1 24.7l9.3 28.2c-8.8 10.7-16 23-20.9 36.2L315.1 313c-9.3 1.9-16.7 9.1-17.8 18.5c-.8 6.7-1.2 13.5-1.2 20.4s.4 13.7 1.2 20.4c1.1 9.4 8.6 16.6 17.8 18.5l29.1 6.1c5 13.3 12.1 25.5 20.9 36.2l-9.3 28.2c-3 9-.5 19 7.1 24.7c4.7 3.5 9.5 6.8 14.6 9.8l5.4 3.1c5 2.8 10.2 5.3 15.5 7.6c8.7 3.7 18.6 .9 25-6.2l19.8-22.2c6.8 1.1 13.8 1.7 20.9 1.7s14.1-.6 20.9-1.7l19.8 22.2zM464 304a48 48 0 1 1 0 96 48 48 0 1 1 0-96z" />
  165. </svg>
  166. }
  167. >
  168. Settings
  169. </DropdownItem>
  170. </DropdownSection>
  171.  
  172. <DropdownItem
  173. key="new"
  174. onClick={handleLogout}
  175. className="text-danger"
  176. startContent={
  177. <svg
  178. className="shrink-0 w-6 aspect-square fill-sky-300"
  179. xmlns="http://www.w3.org/2000/svg"
  180. viewBox="0 0 640 512"
  181. >
  182. <path d="M377.9 105.9L500.7 228.7c7.2 7.2 11.3 17.1 11.3 27.3s-4.1 20.1-11.3 27.3L377.9 406.1c-6.4 6.4-15 9.9-24 9.9c-18.7 0-33.9-15.2-33.9-33.9l0-62.1-128 0c-17.7 0-32-14.3-32-32l0-64c0-17.7 14.3-32 32-32l128 0 0-62.1c0-18.7 15.2-33.9 33.9-33.9c9 0 17.6 3.6 24 9.9zM160 96L96 96c-17.7 0-32 14.3-32 32l0 256c0 17.7 14.3 32 32 32l64 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-64 0c-53 0-96-43-96-96L0 128C0 75 43 32 96 32l64 0c17.7 0 32 14.3 32 32s-14.3 32-32 32z" />
  183. </svg>
  184. }
  185. >
  186. Logout
  187. </DropdownItem>
  188. </DropdownMenu>
  189. </Dropdown>
  190. ) : (
  191. <NavbarItem className="">
  192. <NextLink href="/login">
  193. <button
  194. className={`${clsx(
  195. "cursor-pointer",
  196. "font-clean",
  197. "text-white", // Text color
  198. "text-opacity-60", // Text opacity
  199. "text-base", // Font size
  200. "font-semibold", // Font weight
  201. "uppercase", // Text transform
  202. "tracking-widest", // Letter spacing
  203. "hover:text-opacity-80"
  204. )}`}
  205. >
  206. Login
  207. </button>
  208. </NextLink>
  209. <NextLink href="/register">
  210. <button
  211. className={`${clsx(
  212. "cursor-pointer mx-8",
  213. "font-clean",
  214. "text-white", // Text color
  215. "text-opacity-60", // Text opacity
  216. "text-base", // Font size
  217. "font-semibold", // Font weight
  218. "uppercase", // Text transform
  219. "tracking-widest", // Letter spacing
  220. "hover:text-opacity-80"
  221. )}`}
  222. >
  223. Register
  224. </button>
  225. </NextLink>
  226. </NavbarItem>
  227. )}
  228. </div>
  229. </NavbarContent>
  230.  
  231. <NavbarContent className="sm:hidden basis-1 pl-4" justify="end">
  232. <NavbarMenuToggle />
  233. </NavbarContent>
  234.  
  235. <NavbarMenu>
  236. <div className="mx-4 mt-2 flex flex-col gap-6">
  237. {siteConfig.navMenuItems.map((item, index) => (
  238. <NavbarMenuItem key={`${item}-${index}`}>
  239. <Link
  240. color="foreground"
  241. href="#"
  242. size="lg"
  243. style={{
  244. fontFamily: "Nunito Sans 7pt",
  245. }}
  246. >
  247. {item.label}
  248. </Link>
  249. </NavbarMenuItem>
  250. ))}
  251. </div>
  252. </NavbarMenu>
  253. </NextUINavbar>
  254. );
  255. };
  256.  
Advertisement
Add Comment
Please, Sign In to add comment