From a7b2a0abe98b741b4d86e1ccaeb1704f62fa3043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Mon, 20 May 2024 13:33:32 -0500 Subject: [PATCH] feat: apple inspired navbar --- src/components/Navbar/index.tsx | 289 +++++++++++++++++--------------- src/constants/tools.ts | 3 +- 2 files changed, 152 insertions(+), 140 deletions(-) diff --git a/src/components/Navbar/index.tsx b/src/components/Navbar/index.tsx index 74c90f437..d1a645395 100644 --- a/src/components/Navbar/index.tsx +++ b/src/components/Navbar/index.tsx @@ -18,7 +18,8 @@ import { Text, } from '@radix-ui/themes'; import Link from 'next/link'; -import { Suspense, useEffect, useRef, useState } from 'react'; +import { usePathname } from 'next/navigation'; +import { Suspense, useEffect, useState } from 'react'; import * as styles from '../../app/page.css'; import { REGIONS, UNLOCALIZED_REGION_NAMES } from '../../constants/regions'; import { TOOLS } from '../../constants/tools'; @@ -35,10 +36,10 @@ import { LoggedIn } from './components/LoggedIn'; export const NAVBAR_HEIGHT = 64; export default function Navbar() { - const wideFormat = useWideFormat(480); + const wideFormat = useWideFormat(688 - 32 - 64); const login = useApp((state) => state.login); const [showHamburgerMenu, setShowHamburgerMenu] = useState(false); - const navbar = useRef(null); + const pathname = usePathname(); useEffect(() => { if (!login) return; @@ -53,47 +54,15 @@ export default function Navbar() { } }); - const plugs = ( - <> - setShowHamburgerMenu(false)} - href="https://discord.gg/nDt7AjGJQH" - target="_blank" - style={{ - color: 'inherit', - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - }} - > - - - - setShowHamburgerMenu(false)} - href="https://www.patreon.com/tresabhi" - target="_blank" - style={{ - color: 'inherit', - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - }} - > - - - - ); - return ( setShowHamburgerMenu(true)} - onPointerLeave={(event) => { - if ( - navbar.current === - document.elementFromPoint(event.clientX, event.clientY) - ) { - // false positive bug: https://stackoverflow.com/a/45267167/12294756 - return; - } - - setShowHamburgerMenu(false); - }} - onFocus={() => setShowHamburgerMenu(true)} - onBlur={() => setShowHamburgerMenu(false)} > - setShowHamburgerMenu((state) => !state)} - > - {showHamburgerMenu ? : } - - - setShowHamburgerMenu(false)} - href="/" - style={{ - color: 'inherit', - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - }} - > - - - -
- - {wideFormat && plugs} - - setShowHamburgerMenu(false)}> - - - - - - - - {login && ( - - - - - - - - - - }> - - - - - - )} - - {/* TODO: re-enable in the future */} - {!login && false && ( - - - - - - + {!wideFormat && ( + setShowHamburgerMenu((state) => !state)} > - - Choose your region + {showHamburgerMenu ? : } + + )} - - {REGIONS.map((region) => ( - setShowHamburgerMenu(false)} - key={region} - href={authURL( - region, - typeof window === 'undefined' - ? undefined - : location.href, - )} - > - {UNLOCALIZED_REGION_NAMES[region]} - - ))} - - - - + setShowHamburgerMenu(false)} + href="/" + style={{ + color: 'inherit', + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }} + > + + + + + {wideFormat && ( + + {TOOLS.filter((tool) => !tool.href).map((tool) => { + const selected = pathname.startsWith(`/tools/${tool.id}`); + + return ( + event.preventDefault()} + > + + {tool.title} + + + ); + })} + )} + + + setShowHamburgerMenu(false)} + href="https://discord.gg/nDt7AjGJQH" + target="_blank" + style={{ + color: 'inherit', + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }} + > + + + + setShowHamburgerMenu(false)} + href="https://www.patreon.com/tresabhi" + target="_blank" + style={{ + color: 'inherit', + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }} + > + + + + setShowHamburgerMenu(false)}> + + + + + + + + {login && ( + + + + + + + + + + }> + + + + + + )} + + {/* TODO: re-enable in the future */} + {!login && false && ( + + + + + + + + Choose your region + + + {REGIONS.map((region) => ( + setShowHamburgerMenu(false)} + key={region} + href={authURL( + region, + typeof window === 'undefined' + ? undefined + : location.href, + )} + > + {UNLOCALIZED_REGION_NAMES[region]} + + ))} + + + + + )} + @@ -227,8 +239,7 @@ export default function Navbar() { cursor: tool.disabled ? 'default' : 'pointer', opacity: tool.disabled ? 0.25 : 1, height: 64, - minWidth: 144, - maxWidth: 192, + minWidth: 176, flex: 1, borderRadius: 8, textDecoration: 'none', diff --git a/src/constants/tools.ts b/src/constants/tools.ts index e9ddbe0e4..3a655bca0 100644 --- a/src/constants/tools.ts +++ b/src/constants/tools.ts @@ -38,8 +38,9 @@ export const TOOLS: Tool[] = [ 'Compare tanks statistics and loadouts in World of Tanks Blitz', }, { + // TODO: rename to tracker id: 'session', - title: 'Session tracker', + title: 'Session', description: 'Live session performance tracker', pageDescription: 'Track your stats in real time as you play World of Tanks Blitz',