import navStyles from '../styles/nav.module.scss' import mainStyles from '../styles//main.module.scss' import { Banner } from '../components/Banner' import { Link } from 'react-router-dom' import { appRoutes } from '../routes' import { init as initNostrLogin, launch as launchNostrLoginDialog } from 'nostr-login' import { useEffect } from 'react' import { useAppDispatch, useAppSelector } from '../hooks' import { setIsAuth, setUser } from '../store/reducers/user' import { MetadataController } from '../controllers' import { npubToHex } from '../utils' export const Header = () => { const dispatch = useAppDispatch() const userState = useAppSelector((state) => state.user) useEffect(() => { initNostrLogin({ darkMode: true, localSignup: true, noBanner: true, onAuth: (npub, opts) => { if (opts.type === 'logout') { dispatch(setIsAuth(false)) dispatch(setUser(null)) } else { dispatch(setIsAuth(true)) dispatch(setUser({ npub })) MetadataController.getInstance().then((metadataController) => { metadataController.findMetadata(npub).then((userProfile) => { if (userProfile) { dispatch( setUser({ npub, pubkey: npubToHex(npub)!, ...userProfile }) ) } }) }) } } }) }, [dispatch]) const handleLogin = () => { launchNostrLoginDialog() } return (
) }