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' import { useItems } from '#components/Map/hooks/useItems' import type { Item } from '#src/types/Item' export default function NavBar({ appName, userType }: { appName: string; userType: string }) { const { isAuthenticated, user, logout } = useAuth() const [userProfile, setUserProfile] = useState({} as Item) const items = useItems() useEffect(() => { const profile = user && items.find((i) => i.user_created?.id === user.id && i.layer?.itemType.name === userType) profile ? setUserProfile(profile) : setUserProfile({ id: crypto.randomUUID(), name: user?.first_name ?? '', text: '' }) // eslint-disable-next-line react-hooks/exhaustive-deps }, [user, items]) // useEffect(() => {}, [userProfile]) 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}

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