import { Page, ButtonGroup, Button, useBodyScroll, useMediaQuery, useTheme, Tabs, Loading, Spacer } from "@geist-ui/core"; import { Github as GitHubIcon, UserPlus as SignUpIcon, User as SignInIcon, Home as HomeIcon, Menu as MenuIcon, Tool as SettingsIcon, UserX as SignoutIcon, PlusCircle as NewIcon, List as YourIcon } from "@geist-ui/icons"; import { DriftProps } from "../../pages/_app"; import { useEffect, useMemo, useState } from "react"; import styles from './header.module.css'; import { useRouter } from "next/router"; import useSignedIn from "../../lib/hooks/use-signed-in"; import Mobile from "./controls"; import Controls from "./controls"; import NextLink from 'next/link' const Header = ({ changeTheme, theme }: DriftProps) => { const router = useRouter(); const [selectedTab, setSelectedTab] = useState(); const [expanded, setExpanded] = useState(false) const [, setBodyHidden] = useBodyScroll(null, { scrollLayer: true }) const isMobile = useMediaQuery('xs', { match: 'down' }) const { isLoading, isSignedIn } = useSignedIn({ redirectIfNotAuthed: false }) useEffect(() => { setBodyHidden(expanded) }, [expanded, setBodyHidden]) useEffect(() => { if (!isMobile) { setExpanded(false) } }, [isMobile]) const pages = useMemo(() => [ { name: "Home", href: "/", icon: , condition: true }, { name: "New", href: "/new", icon: , condition: isSignedIn }, { name: "Yours", href: "/mine", icon: , condition: isSignedIn }, // { // name: "Settings", // href: "/settings", // icon: , // condition: isSignedIn // }, { name: "Sign out", action: () => { if (typeof window !== 'undefined') { localStorage.clear(); router.push("/signin"); } }, icon: , condition: isSignedIn }, { name: "Sign in", href: "/signin", icon: , condition: !isSignedIn }, { name: "Sign up", href: "/signup", icon: , condition: !isSignedIn }, { name: "", href: "https://github.com/maxleiter/drift", icon: , condition: true } ], [isSignedIn, router]) useEffect(() => { setSelectedTab(pages.find((page) => { if (page.href && page.href === router.asPath) { return true } })?.href) }, [pages, router, router.pathname]) if (isLoading) { return } return ( {!isMobile &&
{ const nameMatch = pages.find(page => page.name === tab) if (nameMatch?.action) { nameMatch.action() } else { router.push(`${tab}`) } }}> {pages.map((tab, index) => { if (tab.condition) return {tab.icon} {tab.name}} value={tab.href || tab.name} key={`${tab.name}-${index}`} /> else return null })}
}
{isMobile && ( )}
{isMobile && expanded && (
{pages.map((tab, index) => { if (tab.condition) return })}
)}
) } export default Header // {/* {/* // // // // // * /}