2021-04-12 13:05:09 -05:00
|
|
|
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'
|
2021-12-05 11:37:55 -06:00
|
|
|
import { Button, Container, NavDropdown } from 'react-bootstrap'
|
2021-04-28 14:30:14 -05:00
|
|
|
import Price from './price'
|
2021-05-24 19:08:56 -05:00
|
|
|
import { useMe } from './me'
|
2021-07-08 14:52:11 -05:00
|
|
|
import Head from 'next/head'
|
2021-11-28 11:29:17 -06:00
|
|
|
import { signOut, signIn } from 'next-auth/client'
|
2021-07-16 11:47:18 -05:00
|
|
|
import { useLightning } from './lightning'
|
2021-10-21 17:05:06 -05:00
|
|
|
import { useEffect, useState } from 'react'
|
2021-07-16 11:47:18 -05:00
|
|
|
import { randInRange } from '../lib/rand'
|
2022-02-17 11:23:43 -06:00
|
|
|
import { formatSats } from '../lib/format'
|
2021-11-12 16:39:52 -06:00
|
|
|
|
2021-06-24 18:56:01 -05:00
|
|
|
function WalletSummary ({ me }) {
|
2021-11-12 16:39:52 -06:00
|
|
|
if (!me) return null
|
|
|
|
|
|
|
|
return `${formatSats(me.sats)} \\ ${formatSats(me.stacked)}`
|
2021-05-11 10:52:50 -05:00
|
|
|
}
|
2021-03-25 14:29:24 -05:00
|
|
|
|
2022-02-17 11:23:43 -06:00
|
|
|
export default function Header ({ sub }) {
|
2021-04-12 13:05:09 -05:00
|
|
|
const router = useRouter()
|
2021-05-05 13:13:14 -05:00
|
|
|
const path = router.asPath.split('?')[0]
|
2021-12-06 10:32:58 -06:00
|
|
|
const [fired, setFired] = useState()
|
2021-06-24 18:56:01 -05:00
|
|
|
const me = useMe()
|
2022-02-17 11:23:43 -06:00
|
|
|
const prefix = sub ? `/~${sub}` : ''
|
2021-10-21 17:05:06 -05:00
|
|
|
|
2021-04-12 13:05:09 -05:00
|
|
|
const Corner = () => {
|
2021-09-24 18:51:07 -05:00
|
|
|
if (me) {
|
2021-04-12 13:05:09 -05:00
|
|
|
return (
|
2021-05-05 13:13:14 -05:00
|
|
|
<div className='d-flex align-items-center'>
|
2021-08-17 18:59:22 -05:00
|
|
|
<Head>
|
2021-09-24 16:56:51 -05:00
|
|
|
<link rel='shortcut icon' href={me?.hasNewNotes ? '/favicon-notify.png' : '/favicon.png'} />
|
2021-08-17 18:59:22 -05:00
|
|
|
</Head>
|
2021-11-12 16:39:52 -06:00
|
|
|
<div className='position-relative'>
|
2022-03-08 14:51:06 -06:00
|
|
|
<NavDropdown className={styles.dropdown} title={`@${me?.name}`} alignRight>
|
2021-09-24 18:43:30 -05:00
|
|
|
<Link href={'/' + me?.name} passHref>
|
2021-09-24 16:56:51 -05:00
|
|
|
<NavDropdown.Item>
|
|
|
|
profile
|
|
|
|
{me && !me.bio &&
|
|
|
|
<div className='p-1 d-inline-block bg-secondary ml-1'>
|
|
|
|
<span className='invisible'>{' '}</span>
|
|
|
|
</div>}
|
|
|
|
</NavDropdown.Item>
|
2021-06-24 18:56:01 -05:00
|
|
|
</Link>
|
2021-10-26 15:49:37 -05:00
|
|
|
<Link href='/notifications' passHref>
|
2021-09-06 17:36:08 -05:00
|
|
|
<NavDropdown.Item>
|
2021-06-24 18:56:01 -05:00
|
|
|
notifications
|
2021-09-24 16:56:51 -05:00
|
|
|
{me?.hasNewNotes &&
|
2021-07-08 14:52:11 -05:00
|
|
|
<div className='p-1 d-inline-block bg-danger ml-1'>
|
2021-06-24 18:56:01 -05:00
|
|
|
<span className='invisible'>{' '}</span>
|
|
|
|
</div>}
|
|
|
|
</NavDropdown.Item>
|
2021-10-26 15:49:37 -05:00
|
|
|
</Link>
|
2021-06-24 18:56:01 -05:00
|
|
|
<Link href='/wallet' passHref>
|
|
|
|
<NavDropdown.Item>wallet</NavDropdown.Item>
|
|
|
|
</Link>
|
2021-10-14 16:05:37 -05:00
|
|
|
<NavDropdown.Divider />
|
|
|
|
<Link href='/invites' passHref>
|
2021-10-15 18:07:51 -05:00
|
|
|
<NavDropdown.Item>invites
|
|
|
|
{me && !me.hasInvites &&
|
|
|
|
<div className='p-1 d-inline-block bg-success ml-1'>
|
|
|
|
<span className='invisible'>{' '}</span>
|
|
|
|
</div>}
|
|
|
|
</NavDropdown.Item>
|
2021-10-14 16:05:37 -05:00
|
|
|
</Link>
|
2021-05-06 16:15:22 -05:00
|
|
|
<NavDropdown.Divider />
|
2021-11-04 14:22:03 -04:00
|
|
|
<div className='d-flex align-items-center'>
|
|
|
|
<Link href='/settings' passHref>
|
|
|
|
<NavDropdown.Item>settings</NavDropdown.Item>
|
|
|
|
</Link>
|
|
|
|
</div>
|
2021-10-30 11:20:11 -05:00
|
|
|
<NavDropdown.Divider />
|
2021-12-20 16:34:26 -06:00
|
|
|
<NavDropdown.Item onClick={() => signOut({ callbackUrl: '/' })}>logout</NavDropdown.Item>
|
2021-06-24 18:56:01 -05:00
|
|
|
</NavDropdown>
|
2021-09-24 16:56:51 -05:00
|
|
|
{me?.hasNewNotes &&
|
2021-07-08 14:52:11 -05:00
|
|
|
<span className='position-absolute p-1 bg-danger' style={{ top: '5px', right: '0px' }}>
|
2021-06-24 18:56:01 -05:00
|
|
|
<span className='invisible'>{' '}</span>
|
|
|
|
</span>}
|
2021-09-24 16:56:51 -05:00
|
|
|
{me && !me.bio &&
|
|
|
|
<span className='position-absolute p-1 bg-secondary' style={{ bottom: '5px', right: '0px' }}>
|
|
|
|
<span className='invisible'>{' '}</span>
|
|
|
|
</span>}
|
2021-06-24 18:56:01 -05:00
|
|
|
</div>
|
|
|
|
{me &&
|
|
|
|
<Nav.Item>
|
|
|
|
<Link href='/wallet' passHref>
|
2021-08-19 15:34:33 -05:00
|
|
|
<Nav.Link className='text-success px-0 text-nowrap'><WalletSummary me={me} /></Nav.Link>
|
2021-05-06 16:15:22 -05:00
|
|
|
</Link>
|
2021-06-24 18:56:01 -05:00
|
|
|
</Nav.Item>}
|
2021-05-05 13:13:14 -05:00
|
|
|
</div>
|
2021-04-12 13:05:09 -05:00
|
|
|
)
|
|
|
|
} else {
|
2021-12-06 10:32:58 -06:00
|
|
|
if (!fired) {
|
|
|
|
const strike = useLightning()
|
|
|
|
useEffect(() => {
|
|
|
|
setTimeout(strike, randInRange(3000, 10000))
|
2022-01-05 14:37:34 -06:00
|
|
|
setFired(true)
|
2021-12-06 10:32:58 -06:00
|
|
|
}, [router.asPath])
|
|
|
|
}
|
2021-10-15 13:05:34 -05:00
|
|
|
return path !== '/login' && !path.startsWith('/invites') && <Button id='login' onClick={signIn}>login</Button>
|
2021-04-12 13:05:09 -05:00
|
|
|
}
|
2021-03-25 14:29:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-04-12 13:05:09 -05:00
|
|
|
<>
|
2021-04-28 11:30:02 -05:00
|
|
|
<Container className='px-sm-0'>
|
2022-03-08 14:51:06 -06:00
|
|
|
<Navbar className='pb-0 pb-md-1'>
|
2021-10-06 20:20:59 -07:00
|
|
|
<Nav
|
|
|
|
className={styles.navbarNav}
|
|
|
|
activeKey={path}
|
|
|
|
>
|
2022-02-17 11:23:43 -06:00
|
|
|
<div className='d-flex'>
|
|
|
|
<Link href='/' passHref>
|
2022-03-08 14:51:06 -06:00
|
|
|
<Navbar.Brand className={`${styles.brand} d-none d-md-block`}>
|
2022-03-07 12:11:58 -06:00
|
|
|
STACKER NEWS
|
2022-02-17 11:23:43 -06:00
|
|
|
</Navbar.Brand>
|
2021-12-05 11:37:55 -06:00
|
|
|
</Link>
|
2022-02-17 11:23:43 -06:00
|
|
|
<Link href='/' passHref>
|
2022-03-08 14:51:06 -06:00
|
|
|
<Navbar.Brand className={`${styles.brand} d-block d-md-none`}>
|
2022-02-17 11:23:43 -06:00
|
|
|
SN
|
|
|
|
</Navbar.Brand>
|
|
|
|
</Link>
|
|
|
|
</div>
|
2022-03-08 14:51:06 -06:00
|
|
|
<Nav.Item className='d-none d-md-flex'>
|
2022-02-17 11:23:43 -06:00
|
|
|
<Link href={prefix + '/recent'} passHref>
|
|
|
|
<Nav.Link className={styles.navLink}>recent</Nav.Link>
|
2021-12-05 11:37:55 -06:00
|
|
|
</Link>
|
2021-04-13 19:57:32 -05:00
|
|
|
</Nav.Item>
|
2022-02-17 11:23:43 -06:00
|
|
|
{!prefix &&
|
2022-03-08 14:51:06 -06:00
|
|
|
<Nav.Item className='d-none d-md-flex'>
|
2022-02-17 11:23:43 -06:00
|
|
|
<Link href='/top/posts/week' passHref>
|
|
|
|
<Nav.Link className={styles.navLink}>top</Nav.Link>
|
|
|
|
</Link>
|
|
|
|
</Nav.Item>}
|
2022-03-08 14:51:06 -06:00
|
|
|
<Nav.Item className='d-none d-md-flex'>
|
2022-03-07 12:11:58 -06:00
|
|
|
<Link href='/~jobs' passHref>
|
2022-03-08 14:51:06 -06:00
|
|
|
<Nav.Link active={sub === 'jobs'} className={styles.navLink}>jobs</Nav.Link>
|
2022-03-07 12:11:58 -06:00
|
|
|
</Link>
|
2021-04-26 16:55:15 -05:00
|
|
|
</Nav.Item>
|
2022-03-08 14:51:06 -06:00
|
|
|
{me &&
|
|
|
|
<Nav.Item className='d-none d-md-flex'>
|
|
|
|
<Link href={prefix + '/post'} passHref>
|
|
|
|
<Nav.Link className={styles.navLinkButton}>post</Nav.Link>
|
|
|
|
</Link>
|
|
|
|
</Nav.Item>}
|
|
|
|
<Nav.Item className={`text-monospace nav-link px-0 ${me?.name.length > 6 ? 'd-none d-lg-flex' : ''}`}>
|
2021-11-28 11:29:17 -06:00
|
|
|
<Price />
|
2021-04-28 14:30:14 -05:00
|
|
|
</Nav.Item>
|
2021-11-28 11:29:17 -06:00
|
|
|
<Corner />
|
2021-04-13 19:57:32 -05:00
|
|
|
</Nav>
|
2021-11-09 16:43:56 -06:00
|
|
|
</Navbar>
|
2022-03-08 14:51:06 -06:00
|
|
|
<Navbar className='pt-0 pb-1 d-md-none'>
|
|
|
|
<Nav
|
2022-03-10 12:38:48 -06:00
|
|
|
className={`${styles.navbarNav} justify-content-around`}
|
2022-03-08 14:51:06 -06:00
|
|
|
activeKey={path}
|
|
|
|
>
|
|
|
|
<Nav.Item>
|
|
|
|
<Link href={prefix + '/recent'} passHref>
|
|
|
|
<Nav.Link className={styles.navLink}>recent</Nav.Link>
|
|
|
|
</Link>
|
|
|
|
</Nav.Item>
|
|
|
|
{!prefix &&
|
|
|
|
<Nav.Item>
|
|
|
|
<Link href='/top/posts/week' passHref>
|
|
|
|
<Nav.Link className={styles.navLink}>top</Nav.Link>
|
|
|
|
</Link>
|
|
|
|
</Nav.Item>}
|
|
|
|
<Nav.Item>
|
|
|
|
<Link href='/~jobs' passHref>
|
|
|
|
<Nav.Link active={sub === 'jobs'} className={styles.navLink}>jobs</Nav.Link>
|
|
|
|
</Link>
|
|
|
|
</Nav.Item>
|
|
|
|
{me &&
|
|
|
|
<Nav.Item>
|
|
|
|
<Link href={prefix + '/post'} passHref>
|
|
|
|
<Nav.Link className={styles.navLinkButton}>post</Nav.Link>
|
|
|
|
</Link>
|
|
|
|
</Nav.Item>}
|
|
|
|
</Nav>
|
|
|
|
</Navbar>
|
2021-04-28 11:30:02 -05:00
|
|
|
</Container>
|
2021-04-12 13:05:09 -05:00
|
|
|
</>
|
2021-03-25 14:29:24 -05:00
|
|
|
)
|
|
|
|
}
|