import Bars3Icon from '@heroicons/react/16/solid/Bars3Icon' import EllipsisVerticalIcon from '@heroicons/react/16/solid/EllipsisVerticalIcon' import QuestionMarkIcon from '@heroicons/react/24/outline/QuestionMarkCircleIcon' import { useEffect, useRef, useState } from 'react' import { Link, useLocation } from 'react-router-dom' import { toast } from 'react-toastify' import { useAuth } from '#components/Auth/useAuth' import { useItems } from '#components/Map/hooks/useItems' import { ThemeControl } from '#components/Templates/ThemeControl' import { useAppState, useSetAppState } from './hooks/useAppState' import type { Item } from '#types/Item' export default function NavBar({ appName }: { appName: string }) { const { isAuthenticated, user, logout } = useAuth() const [userProfile, setUserProfile] = useState({} as Item) const items = useItems() const appState = useAppState() const setAppState = useSetAppState() const toggleSidebar = () => { setAppState({ sideBarOpen: !appState.sideBarOpen }) } useEffect(() => { const profile = user && items.find((i) => i.user_created?.id === user.id && i.layer?.userProfileLayer) profile ? setUserProfile(profile) : setUserProfile({ id: crypto.randomUUID(), name: user?.first_name ?? '', text: '' }) }, [user, items]) const nameRef = useRef(null) const [nameWidth, setNameWidth] = useState(0) const location = useLocation() const [showNav, setShowNav] = useState(false) useEffect(() => { showNav && nameRef.current && setNameWidth(nameRef.current.scrollWidth) }, [nameRef, appName, showNav]) useEffect(() => { const params = new URLSearchParams(location.search) const embedded = params.get('embedded') embedded !== 'true' && setShowNav(true) }, [location]) const onLogout = async () => { await toast.promise(logout(), { success: { render() { return 'Bye bye' }, // other options icon: '👋', }, error: { render({ data }) { return JSON.stringify(data) }, }, pending: 'logging out ..', }) } if (showNav) { return ( <>

{appName}

{appState.showThemeControl && } {isAuthenticated ? (
{userProfile.image && (
)}
{userProfile.name || user?.first_name}
) : (
Login
Sign Up
  • Login
  • Sign Up
)}
) } else return <> }