import Navbar from 'react-bootstrap/Navbar' import Nav from 'react-bootstrap/Nav' import Link from 'next/link' import styles from './header.module.css' import { useRouter } from 'next/router' import { Button, Container, NavDropdown } from 'react-bootstrap' import Price from './price' import { useMe } from './me' import Head from 'next/head' import { signOut, signIn } from 'next-auth/client' import { useLightning } from './lightning' import { useEffect, useState } from 'react' import { randInRange } from '../lib/rand' import { formatSats } from '../lib/format' import NoteIcon from '../svgs/notification-4-fill.svg' import { useQuery, gql } from '@apollo/client' function WalletSummary ({ me }) { if (!me) return null return `${formatSats(me.sats)}` } export default function Header ({ sub }) { const router = useRouter() const path = router.asPath.split('?')[0] const [fired, setFired] = useState() const me = useMe() const prefix = sub ? `/~${sub}` : '' const { data: subLatestPost } = useQuery(gql` query subLatestPost($name: ID!) { subLatestPost(name: $name) } `, { variables: { name: 'jobs' }, pollInterval: 600000, fetchPolicy: 'network-only' }) const [lastCheckedJobs, setLastCheckedJobs] = useState(new Date().getTime()) useEffect(() => { if (me) { setLastCheckedJobs(me.lastCheckedJobs) } else { if (sub === 'jobs') { localStorage.setItem('lastCheckedJobs', new Date().getTime()) } setLastCheckedJobs(localStorage.getItem('lastCheckedJobs')) } }) const Corner = () => { if (me) { return (
{me?.hasNewNotes && {' '} }
profile {me && !me.bioId &&
{' '}
}
wallet satistics invites {me && !me.hasInvites &&
{' '}
}
settings
signOut({ callbackUrl: '/' })}>logout
{me && !me.bioId && {' '} }
{me && }
) } else { if (!fired) { const strike = useLightning() useEffect(() => { setTimeout(strike, randInRange(3000, 10000)) setFired(true) }, [router.asPath]) } return path !== '/login' && !path.startsWith('/invites') && } } const NavItems = ({ className }) => { return ( <> recent {!prefix && top }
jobs {sub !== 'jobs' && (!me || me.noteJobIndicator) && (!lastCheckedJobs || lastCheckedJobs < subLatestPost?.subLatestPost) && {' '} }
{me && post } ) } return ( <> ) }