import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { IconName } from '@fortawesome/fontawesome-svg-core' import { Dialog, Transition } from '@headlessui/react' import toast, { Toaster } from 'react-hot-toast' import { useHotkeys } from 'react-hotkeys-hook' import Link from 'next/link' import Image from 'next/image' import { useRouter } from 'next/router' import { Fragment, useEffect, useState } from 'react' import { useTranslation } from 'next-i18next' import siteConfig from '../config/site.config' import SearchModal from './SearchModal' import useDeviceOS from '../utils/useDeviceOS' const Navbar = () => { const router = useRouter() const os = useDeviceOS() const [tokenPresent, setTokenPresent] = useState(false) const [isOpen, setIsOpen] = useState(false) const [searchOpen, setSearchOpen] = useState(false) const openSearchBox = () => setSearchOpen(true) useHotkeys(`${os === 'mac' ? 'cmd' : 'ctrl'}+k`, openSearchBox) useEffect(() => { const storedToken = () => { for (const r of siteConfig.protectedRoutes) { if (localStorage.hasOwnProperty(r)) { return true } } return false } setTokenPresent(storedToken()) }, []) const { t } = useTranslation() const clearTokens = () => { setIsOpen(false) siteConfig.protectedRoutes.forEach(r => { localStorage.removeItem(r) }) toast.success(t('Cleared all tokens')) setTimeout(() => { router.reload() }, 1000) } return (