import Link from 'next/link' import { Button, Dropdown, Nav, Navbar } from 'react-bootstrap' import styles from '../header.module.css' import { useRouter } from 'next/router' import BackArrow from '../../svgs/arrow-left-line.svg' import { useCallback, useEffect, useState } from 'react' import Price from '../price' import SubSelect from '../sub-select' import { useQuery } from '@apollo/client' import { HAS_NOTIFICATIONS } from '../../fragments/notifications' import { ANON_USER_ID, BALANCE_LIMIT_MSATS, SSR } from '../../lib/constants' import { clearNotifications } from '../../lib/badge' import Head from 'next/head' import NoteIcon from '../../svgs/notification-4-fill.svg' import { useMe } from '../me' import HiddenWalletSummary from '../hidden-wallet-summary' import { abbrNum, msatsToSats } from '../../lib/format' import { useServiceWorker } from '../serviceworker' import { signOut } from 'next-auth/react' import Hat from '../hat' import { randInRange } from '../../lib/rand' import { useLightning } from '../lightning' import LightningIcon from '../../svgs/bolt.svg' import SearchIcon from '../../svgs/search-line.svg' import classNames from 'classnames' import SnIcon from '@/svgs/sn.svg' export function Brand ({ className }) { return ( ) } export function noNavSelect ({ path, pathname }) { return ( path.startsWith('/items') || path.endsWith('/post') || path.endsWith('/edit') || path.endsWith('/notifications') || path.endsWith('/search') || path.startsWith('/wallet') || path.startsWith('/rewards') || path.startsWith('/referrals') || path.startsWith('/live') || path.startsWith('/settings') || path.startsWith('/referrals') || path.startsWith('/invites') || path.startsWith('/stackers') || path.startsWith('/satistics') || path.startsWith('/withdrawals') || path.startsWith('/invoices') || pathname.startsWith('/[name]') || path.startsWith('/territory') ) } export function Back () { const router = useRouter() const [back, setBack] = useState(router.asPath !== '/') useEffect(() => { setBack(router.asPath !== '/' && (typeof window.navigation === 'undefined' || window.navigation.canGoBack === undefined || window?.navigation.canGoBack)) }, [router.asPath]) if (!back) return null return ( { if (back) { router.back() } else { router.push('/') } }} > ) } export function BackOrBrand ({ className }) { const router = useRouter() const [back, setBack] = useState(router.asPath !== '/') useEffect(() => { setBack(router.asPath !== '/' && (typeof window.navigation === 'undefined' || window.navigation.canGoBack === undefined || window?.navigation.canGoBack)) }, [router.asPath]) return (
{back ? : }
) } export function SearchItem ({ prefix, className }) { return ( ) } export function NavPrice ({ className }) { return ( ) } const PREPEND_SUBS = ['home'] const APPEND_SUBS = [{ label: '--------', items: ['create'] }] export function NavSelect ({ sub: subName, className, size }) { const sub = subName || 'home' return ( ) } export function NavNotifications ({ className }) { const { data } = useQuery(HAS_NOTIFICATIONS, SSR ? {} : { pollInterval: 30000, nextFetchPolicy: 'cache-and-network', onCompleted: ({ hasNewNotes }) => { if (!hasNewNotes) { clearNotifications() } } }) return ( <> {data?.hasNewNotes && {' '} } ) } export function WalletSummary () { const me = useMe() if (!me) return null if (me.privates?.hideWalletBalance) { return } return `${abbrNum(me.privates?.sats)}` } export function NavWalletSummary () { const me = useMe() const walletLimitReached = me?.privates?.sats >= msatsToSats(BALANCE_LIMIT_MSATS) return ( ) } export function MeDropdown ({ me, dropNavKey }) { if (!me) return null const { registration: swRegistration, togglePushSubscription } = useServiceWorker() return (
{`@${me.name}`} profile {me && !me.bioId &&
{' '}
}
bookmarks wallet satistics referrals
settings
{ try { // order is important because we need to be logged in to delete push subscription on server const pushSubscription = await swRegistration?.pushManager.getSubscription() if (pushSubscription) { await togglePushSubscription() } } catch (err) { // don't prevent signout because of an unsubscription error console.error(err) } await signOut({ callbackUrl: '/' }) }} >logout
{!me.bioId && {' '} }
) } export function SignUpButton ({ handleLogin, className = 'py-0' }) { return ( ) } export function LoginButtons () { const router = useRouter() const handleLogin = useCallback(async pathname => await router.push({ pathname, query: { callbackUrl: window.location.origin + router.asPath } }), [router]) return ( <> ) } export function AnonDropdown ({ path }) { const strike = useLightning() useEffect(() => { if (!window.localStorage.getItem('striked')) { const to = setTimeout(() => { strike() window.localStorage.setItem('striked', 'yep') }, randInRange(3000, 10000)) return () => clearTimeout(to) } }, []) return (
@anon
) } export function Sorts ({ sub, prefix, className }) { return ( <> hot recent {/* random */} {sub !== 'jobs' && top } ) } export function PostItem ({ className, prefix }) { return ( post ) } export function MeCorner ({ dropNavKey, me, className }) { return (
) } export function AnonCorner ({ dropNavKey, className }) { return (
) }