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 siteConfig from '../config/site.json' 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 clearTokens = () => { setIsOpen(false) siteConfig.protectedRoutes.forEach(r => { localStorage.removeItem(r) }) toast.success('Cleared all tokens') setTimeout(() => { router.reload() }, 1000) } return (
icon {siteConfig.title}
{siteConfig.links.length !== 0 && siteConfig.links.map((l: { name: string; link: string }) => ( {l.name} ))} {siteConfig.email && ( Email )} {tokenPresent && ( )}
setIsOpen(false)}>
{/* This element is to trick the browser into centering the modal contents. */}
Clear all tokens?

These tokens are used to authenticate yourself into password protected folders, clearing them means that you will need to re-enter the passwords again.

{siteConfig.protectedRoutes.map((r, i) => (
{r}
))}
) } export default Navbar