mirror of
https://github.com/Nezumi-2711/onedrive-vercel-index.git
synced 2026-09-22 13:38:45 +00:00
navbar logout and other custom icons
This commit is contained in:
@@ -27,6 +27,7 @@ const Auth: FunctionComponent<{ redirect: string }> = ({ redirect }) => {
|
|||||||
|
|
||||||
<input
|
<input
|
||||||
className="font-mono p-2 bg-blue-50 dark:bg-gray-600 dark:text-white rounded focus:ring focus:ring-blue-300 dark:focus:ring-blue-700 focus:outline-none"
|
className="font-mono p-2 bg-blue-50 dark:bg-gray-600 dark:text-white rounded focus:ring focus:ring-blue-300 dark:focus:ring-blue-700 focus:outline-none"
|
||||||
|
autoFocus
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="************"
|
placeholder="************"
|
||||||
value={token}
|
value={token}
|
||||||
|
|||||||
+48
-20
@@ -1,17 +1,31 @@
|
|||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
|
import { IconName } from '@fortawesome/fontawesome-svg-core'
|
||||||
import { Dialog, Transition } from '@headlessui/react'
|
import { Dialog, Transition } from '@headlessui/react'
|
||||||
import toast, { Toaster } from 'react-hot-toast'
|
import toast, { Toaster } from 'react-hot-toast'
|
||||||
|
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { Fragment, useState } from 'react'
|
import { Fragment, useEffect, useState } from 'react'
|
||||||
|
|
||||||
import siteConfig from '../config/site.json'
|
import siteConfig from '../config/site.json'
|
||||||
|
|
||||||
const Navbar = () => {
|
const Navbar = () => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const [tokenPresent, setTokenPresent] = useState(false)
|
||||||
const [isOpen, setIsOpen] = useState(false)
|
const [isOpen, setIsOpen] = useState(false)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const storedToken = () => {
|
||||||
|
for (const r of siteConfig.protectedRoutes) {
|
||||||
|
if (localStorage.hasOwnProperty(r)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
setTokenPresent(storedToken())
|
||||||
|
}, [])
|
||||||
|
|
||||||
const clearTokens = () => {
|
const clearTokens = () => {
|
||||||
setIsOpen(false)
|
setIsOpen(false)
|
||||||
|
|
||||||
@@ -30,25 +44,39 @@ const Navbar = () => {
|
|||||||
<div className="max-w-4xl w-full mx-auto flex items-center justify-between">
|
<div className="max-w-4xl w-full mx-auto flex items-center justify-between">
|
||||||
<Toaster />
|
<Toaster />
|
||||||
|
|
||||||
<h1 className="font-bold text-xl p-2 rounded dark:text-white hover:opacity-80">
|
<Link href="/">
|
||||||
<Link href="/">{siteConfig.title}</Link>
|
<a className="flex items-center space-x-2 font-bold text-xl p-2 dark:text-white hover:opacity-80">
|
||||||
</h1>
|
<FontAwesomeIcon icon="cloud" />
|
||||||
<div className="flex items-center">
|
<span className="hidden sm:block">{siteConfig.title}</span>
|
||||||
<button
|
|
||||||
className="flex space-x-2 items-center p-3 rounded dark:text-white hover:opacity-80"
|
|
||||||
onClick={() => setIsOpen(true)}
|
|
||||||
>
|
|
||||||
<FontAwesomeIcon icon="key" />
|
|
||||||
<span>Logout</span>
|
|
||||||
</button>
|
|
||||||
<a
|
|
||||||
href="https://github.com/spencerwooo/onedrive-vercel-index"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="p-2 rounded dark:text-white hover:opacity-80"
|
|
||||||
>
|
|
||||||
<FontAwesomeIcon icon={['fab', 'github']} size="lg" />
|
|
||||||
</a>
|
</a>
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
<div className="flex items-center">
|
||||||
|
{siteConfig.contacts.map((c, i) => (
|
||||||
|
<a
|
||||||
|
key={i}
|
||||||
|
href={c.link}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="p-2 rounded hover:bg-gray-200 dark:text-white dark:hover:bg-gray-700"
|
||||||
|
>
|
||||||
|
{c.platform === 'email' ? (
|
||||||
|
<FontAwesomeIcon icon={['far', 'envelope']} size="lg" />
|
||||||
|
) : (
|
||||||
|
<FontAwesomeIcon icon={['fab', c.platform as IconName]} size="lg" />
|
||||||
|
)}
|
||||||
|
</a>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{tokenPresent && (
|
||||||
|
<button
|
||||||
|
className="flex space-x-2 items-center p-2 rounded hover:bg-gray-200 dark:text-white dark:hover:bg-gray-700"
|
||||||
|
onClick={() => setIsOpen(true)}
|
||||||
|
>
|
||||||
|
<span>Logout</span>
|
||||||
|
<FontAwesomeIcon icon="sign-out-alt" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -64,7 +92,7 @@ const Navbar = () => {
|
|||||||
leaveFrom="opacity-100"
|
leaveFrom="opacity-100"
|
||||||
leaveTo="opacity-0"
|
leaveTo="opacity-0"
|
||||||
>
|
>
|
||||||
<Dialog.Overlay className="fixed inset-0" />
|
<Dialog.Overlay className="fixed inset-0 bg-gray-50 dark:bg-gray-800" />
|
||||||
</Transition.Child>
|
</Transition.Child>
|
||||||
|
|
||||||
{/* This element is to trick the browser into centering the modal contents. */}
|
{/* This element is to trick the browser into centering the modal contents. */}
|
||||||
|
|||||||
@@ -4,5 +4,15 @@
|
|||||||
"protectedRoutes": [
|
"protectedRoutes": [
|
||||||
"/🌞 Private folder/u-need-a-password",
|
"/🌞 Private folder/u-need-a-password",
|
||||||
"/🥟 Some test files/Protected route"
|
"/🥟 Some test files/Protected route"
|
||||||
|
],
|
||||||
|
"contacts": [
|
||||||
|
{
|
||||||
|
"platform": "email",
|
||||||
|
"link": "mailto:spencer.wushangbo@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"platform": "github",
|
||||||
|
"link": "https://github.com/spencerwooo/onedrive-vercel-index"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -19,6 +19,7 @@ import {
|
|||||||
faCopy,
|
faCopy,
|
||||||
faArrowAltCircleDown,
|
faArrowAltCircleDown,
|
||||||
faTrashAlt,
|
faTrashAlt,
|
||||||
|
faEnvelope,
|
||||||
} from '@fortawesome/free-regular-svg-icons'
|
} from '@fortawesome/free-regular-svg-icons'
|
||||||
import {
|
import {
|
||||||
faPlus,
|
faPlus,
|
||||||
@@ -32,6 +33,8 @@ import {
|
|||||||
faUndo,
|
faUndo,
|
||||||
faBook,
|
faBook,
|
||||||
faKey,
|
faKey,
|
||||||
|
faSignOutAlt,
|
||||||
|
faCloud,
|
||||||
} from '@fortawesome/free-solid-svg-icons'
|
} from '@fortawesome/free-solid-svg-icons'
|
||||||
import { faGithub, faMarkdown } from '@fortawesome/free-brands-svg-icons'
|
import { faGithub, faMarkdown } from '@fortawesome/free-brands-svg-icons'
|
||||||
|
|
||||||
@@ -65,7 +68,10 @@ library.add(
|
|||||||
faBook,
|
faBook,
|
||||||
faArrowAltCircleDown,
|
faArrowAltCircleDown,
|
||||||
faKey,
|
faKey,
|
||||||
faTrashAlt
|
faTrashAlt,
|
||||||
|
faSignOutAlt,
|
||||||
|
faEnvelope,
|
||||||
|
faCloud
|
||||||
)
|
)
|
||||||
|
|
||||||
function MyApp({ Component, pageProps }: AppProps) {
|
function MyApp({ Component, pageProps }: AppProps) {
|
||||||
|
|||||||
Reference in New Issue
Block a user