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 SwitchLang from './SwitchLang' 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`, e => { openSearchBox() e.preventDefault() }) 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 (
icon {siteConfig.title}
{siteConfig.links.length !== 0 && siteConfig.links.map((l: { name: string; link: string }) => ( { // Append link name comments here to add translations // t('Weibo') t(l.name) } ))} {siteConfig.email && ( {t('Email')} )} {tokenPresent && ( )}
setIsOpen(false)}>
{/* This element is to trick the browser into centering the modal contents. */}
{t('Clear all tokens?')}

{t('These tokens are used to authenticate yourself into password protected folders, ') + t('clearing them means that you will need to re-enter the passwords again.')}

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