lev-stake-sol/components/TopBar.tsx

89 lines
3.0 KiB
TypeScript
Raw Normal View History

2023-09-18 21:41:08 -07:00
import { useEffect, useState } from 'react'
2024-02-25 17:32:58 -08:00
import { ExclamationTriangleIcon } from '@heroicons/react/20/solid'
2023-09-12 17:37:41 -07:00
import { useWallet } from '@solana/wallet-adapter-react'
import ConnectedMenu from './wallet/ConnectedMenu'
import ConnectWalletButton from './wallet/ConnectWalletButton'
import useOnlineStatus from 'hooks/useOnlineStatus'
2023-09-18 22:17:57 -07:00
import ThemeToggle from './ThemeToggle'
2023-09-24 05:55:00 -07:00
import Link from 'next/link'
import { useRouter } from 'next/router'
2023-09-25 21:15:02 -07:00
import BoostLogo from './BoostLogo'
2023-09-12 17:37:41 -07:00
const TopBar = () => {
const { connected } = useWallet()
const [copied, setCopied] = useState('')
const isOnline = useOnlineStatus()
2023-09-24 05:55:00 -07:00
const router = useRouter()
const { pathname } = router
2023-09-12 17:37:41 -07:00
useEffect(() => {
setTimeout(() => setCopied(''), 2000)
}, [copied])
return (
2024-02-25 17:32:58 -08:00
<div className="mb-8 grid h-20 grid-cols-3 px-6">
<div className="col-span-1 flex items-center">
2024-02-21 17:05:33 -08:00
<Link href="/" shallow={true}>
<div className="group flex items-center">
<BoostLogo className="h-auto w-12 shrink-0 cursor-pointer group-hover:animate-shake" />
<span className="text-shadow ml-2 hidden text-[32px] font-black text-th-bkg-1 md:block">
Boost!
</span>
<div className="ml-2.5 hidden rounded border border-th-fgd-1 bg-th-active px-1.5 py-1 md:block">
<span className="block font-mono text-xxs font-black leading-none text-th-fgd-1">
v2
</span>
</div>
</div>
</Link>
</div>
2024-02-25 17:32:58 -08:00
<div className="col-span-1 flex items-center justify-center space-x-4">
2024-02-25 21:09:00 -08:00
<NavLink active={pathname === '/'} path="/" text="Boost!" />
2024-02-25 12:13:47 -08:00
<NavLink active={pathname === '/stats'} path="/stats" text="Stats" />
2024-02-21 17:05:33 -08:00
<NavLink active={pathname === '/faqs'} path="/faqs" text="FAQs" />
2024-02-25 17:32:58 -08:00
</div>
<div className="col-span-1 flex items-center justify-end">
2024-02-21 17:05:33 -08:00
<div className="flex space-x-3">
<ThemeToggle />
{connected ? <ConnectedMenu /> : <ConnectWalletButton />}
2023-09-25 06:48:39 -07:00
</div>
2023-09-12 17:37:41 -07:00
</div>
2023-09-25 06:48:39 -07:00
{!isOnline ? (
2023-09-26 05:15:53 -07:00
<div className="bg-th-down absolute left-1/2 top-3 z-10 flex h-10 w-max -translate-x-1/2 items-center rounded-full px-4 py-2 md:top-8">
2023-09-25 07:56:46 -07:00
<ExclamationTriangleIcon className="h-5 w-5 shrink-0 text-th-fgd-1" />
2023-09-25 06:48:39 -07:00
<p className="ml-2 text-th-fgd-1">
Your connection appears to be offline
</p>
</div>
) : null}
2023-09-12 17:37:41 -07:00
</div>
)
}
export default TopBar
2023-09-24 05:55:00 -07:00
2023-09-26 13:09:44 -07:00
const NavLink = ({
active,
path,
text,
2024-02-20 14:18:10 -08:00
target,
2023-09-26 13:09:44 -07:00
}: {
active: boolean
path: string
text: string
2024-02-20 14:18:10 -08:00
target?: string
2023-09-26 13:09:44 -07:00
}) => {
2023-09-24 05:55:00 -07:00
return (
2024-02-20 14:18:10 -08:00
<Link target={target ? target : undefined} href={path} shallow={true}>
2023-09-24 05:55:00 -07:00
<span
2024-02-25 21:09:00 -08:00
className={`default-transition flex items-center rounded-md border-th-bkg-3 bg-th-bkg-1 px-2 py-0.5 text-sm font-bold md:text-base md:hover:text-th-link-hover ${
active ? 'border-t-2 text-th-fgd-1' : 'border-b-2 text-th-fgd-4'
2023-09-24 05:55:00 -07:00
}`}
>
{text}
</span>
</Link>
)
}