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-05-05 13:13:14 -05: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-06-24 18:56:01 -05:00
|
|
|
import { useApolloClient } from '@apollo/client'
|
2021-07-08 14:52:11 -05:00
|
|
|
import Head from 'next/head'
|
2021-07-16 02:09:20 -05:00
|
|
|
import { signOut, signIn, useSession } from 'next-auth/client'
|
2021-07-16 11:47:18 -05:00
|
|
|
import { useLightning } from './lightning'
|
|
|
|
import { useEffect } from 'react'
|
|
|
|
import { randInRange } from '../lib/rand'
|
2021-05-11 10:52:50 -05:00
|
|
|
|
2021-06-24 18:56:01 -05:00
|
|
|
function WalletSummary ({ me }) {
|
2021-08-18 08:52:45 -05:00
|
|
|
return `${me.sats} \\ ${me.stacked}`
|
2021-05-11 10:52:50 -05:00
|
|
|
}
|
2021-03-25 14:29:24 -05:00
|
|
|
|
|
|
|
export default function Header () {
|
|
|
|
const [session, loading] = useSession()
|
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-06-24 18:56:01 -05:00
|
|
|
const me = useMe()
|
|
|
|
const client = useApolloClient()
|
2021-03-25 14:29:24 -05:00
|
|
|
|
2021-04-12 13:05:09 -05:00
|
|
|
const Corner = () => {
|
|
|
|
if (loading) {
|
|
|
|
return null
|
|
|
|
}
|
2021-03-25 14:29:24 -05:00
|
|
|
|
2021-04-12 13:05:09 -05:00
|
|
|
if (session) {
|
|
|
|
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>
|
|
|
|
<link rel='shortcut icon' href={me && me.hasNewNotes ? '/favicon-notify.png' : '/favicon.png'} />
|
|
|
|
</Head>
|
2021-08-18 11:49:59 -05:00
|
|
|
<div className='position-relative mr-1'>
|
2021-08-17 18:59:22 -05:00
|
|
|
<NavDropdown className='px-0' title={`@${session.user.name}`} alignRight>
|
2021-06-24 18:56:01 -05:00
|
|
|
<Link href={'/' + session.user.name} passHref>
|
|
|
|
<NavDropdown.Item>profile</NavDropdown.Item>
|
|
|
|
</Link>
|
|
|
|
<Link href='/notifications' passHref>
|
|
|
|
<NavDropdown.Item onClick={() => {
|
|
|
|
// when it's a fresh click evict old notification cache
|
2021-08-17 18:59:22 -05:00
|
|
|
client.cache.evict({ id: 'ROOT_QUERY', fieldName: 'notifications' })
|
2021-06-24 18:56:01 -05:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
notifications
|
|
|
|
{me && 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>
|
|
|
|
</Link>
|
|
|
|
<Link href='/wallet' passHref>
|
|
|
|
<NavDropdown.Item>wallet</NavDropdown.Item>
|
|
|
|
</Link>
|
|
|
|
<div>
|
|
|
|
<NavDropdown.Divider />
|
|
|
|
<Link href='/recent' passHref>
|
|
|
|
<NavDropdown.Item>recent</NavDropdown.Item>
|
|
|
|
</Link>
|
|
|
|
{session
|
|
|
|
? (
|
|
|
|
<Link href='/post' passHref>
|
|
|
|
<NavDropdown.Item>post</NavDropdown.Item>
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
: <NavDropdown.Item onClick={signIn}>post</NavDropdown.Item>}
|
|
|
|
<NavDropdown.Item href='https://bitcoinerjobs.co' target='_blank'>jobs</NavDropdown.Item>
|
|
|
|
</div>
|
2021-05-06 16:15:22 -05:00
|
|
|
<NavDropdown.Divider />
|
2021-06-24 18:56:01 -05:00
|
|
|
<NavDropdown.Item onClick={signOut}>logout</NavDropdown.Item>
|
|
|
|
</NavDropdown>
|
|
|
|
{me && 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>}
|
|
|
|
</div>
|
|
|
|
{me &&
|
|
|
|
<Nav.Item>
|
|
|
|
<Link href='/wallet' passHref>
|
|
|
|
<Nav.Link className='text-success px-0'><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-07-16 11:47:18 -05:00
|
|
|
const strike = useLightning()
|
|
|
|
useEffect(() => {
|
|
|
|
setTimeout(strike, randInRange(3000, 10000))
|
2021-07-16 12:32:54 -05:00
|
|
|
}, [router.asPath])
|
2021-07-16 02:23:29 -05:00
|
|
|
return path !== '/login' && <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'>
|
|
|
|
<Navbar className={styles.navbar}>
|
2021-05-05 13:13:14 -05:00
|
|
|
<Nav className='w-100 justify-content-between flex-wrap align-items-center' activeKey={path}>
|
2021-04-28 11:30:02 -05:00
|
|
|
<Link href='/' passHref>
|
2021-05-06 16:15:22 -05:00
|
|
|
<Navbar.Brand className={`${styles.brand} d-none d-sm-block`}>STACKER NEWS</Navbar.Brand>
|
2021-04-28 16:30:32 -05:00
|
|
|
</Link>
|
|
|
|
<Link href='/' passHref>
|
2021-05-06 16:15:22 -05:00
|
|
|
<Navbar.Brand className={`${styles.brand} d-block d-sm-none`}>SN</Navbar.Brand>
|
2021-04-28 11:30:02 -05:00
|
|
|
</Link>
|
2021-05-06 16:15:22 -05:00
|
|
|
<Nav.Item className='d-md-flex d-none'>
|
2021-04-13 19:57:32 -05:00
|
|
|
<Link href='/recent' passHref>
|
2021-04-28 11:30:02 -05:00
|
|
|
<Nav.Link className={styles.navLink}>recent</Nav.Link>
|
2021-04-13 19:57:32 -05:00
|
|
|
</Link>
|
|
|
|
</Nav.Item>
|
2021-05-06 16:15:22 -05:00
|
|
|
<Nav.Item className='d-md-flex d-none'>
|
2021-05-20 14:41:21 -05:00
|
|
|
{session
|
|
|
|
? (
|
|
|
|
<Link href='/post' passHref>
|
|
|
|
<Nav.Link className={styles.navLink}>post</Nav.Link>
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
: <Nav.Link className={styles.navLink} onClick={signIn}>post</Nav.Link>}
|
2021-04-13 19:57:32 -05:00
|
|
|
</Nav.Item>
|
2021-05-06 16:15:22 -05:00
|
|
|
<Nav.Item className='d-md-flex d-none'>
|
2021-04-28 11:30:02 -05:00
|
|
|
<Nav.Link href='https://bitcoinerjobs.co' target='_blank' className={styles.navLink}>jobs</Nav.Link>
|
2021-04-26 16:55:15 -05:00
|
|
|
</Nav.Item>
|
2021-05-12 18:04:19 -05:00
|
|
|
<Nav.Item className='text-monospace' style={{ opacity: '.5' }}>
|
2021-04-28 14:30:14 -05:00
|
|
|
<Price />
|
|
|
|
</Nav.Item>
|
2021-04-13 19:57:32 -05:00
|
|
|
<Corner />
|
|
|
|
</Nav>
|
2021-04-28 11:30:02 -05:00
|
|
|
</Navbar>
|
|
|
|
</Container>
|
2021-04-12 13:05:09 -05:00
|
|
|
</>
|
2021-03-25 14:29:24 -05:00
|
|
|
)
|
|
|
|
}
|
2021-07-07 13:34:21 -05:00
|
|
|
|
|
|
|
export function HeaderPreview () {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Container className='px-sm-0'>
|
|
|
|
<Navbar className={styles.navbar}>
|
|
|
|
<Nav className='w-100 justify-content-between flex-wrap align-items-center'>
|
|
|
|
<Link href='/' passHref>
|
|
|
|
<Navbar.Brand className={`${styles.brand} d-none d-sm-block`}>STACKER NEWS</Navbar.Brand>
|
|
|
|
</Link>
|
2021-07-07 19:15:27 -05:00
|
|
|
<Nav.Item className='text-monospace' style={{ opacity: '.5' }}>
|
|
|
|
<Price />
|
|
|
|
</Nav.Item>
|
2021-07-07 13:34:21 -05:00
|
|
|
</Nav>
|
|
|
|
</Navbar>
|
|
|
|
</Container>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|