stacker.news/components/header.js

89 lines
3.1 KiB
JavaScript
Raw Normal View History

2021-03-25 19:29:24 +00:00
import { signOut, signIn, useSession } from 'next-auth/client'
2021-04-12 18:05:09 +00: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 18:13:14 +00:00
import { Button, Container, NavDropdown } from 'react-bootstrap'
2021-04-28 19:30:14 +00:00
import Price from './price'
2021-03-25 19:29:24 +00:00
export default function Header () {
const [session, loading] = useSession()
2021-04-12 18:05:09 +00:00
const router = useRouter()
2021-05-05 18:13:14 +00:00
const path = router.asPath.split('?')[0]
2021-03-25 19:29:24 +00:00
2021-04-12 18:05:09 +00:00
const Corner = () => {
if (loading) {
return null
}
2021-03-25 19:29:24 +00:00
2021-04-12 18:05:09 +00:00
if (session) {
return (
2021-05-05 18:13:14 +00:00
<div className='d-flex align-items-center'>
2021-05-06 21:15:22 +00:00
<NavDropdown className='pl-0' title={`@${session.user.name}`} alignRight>
2021-05-05 18:13:14 +00:00
<Link href={'/' + session.user.name} passHref>
<NavDropdown.Item>profile</NavDropdown.Item>
</Link>
2021-05-06 21:15:22 +00:00
<Link href='/wallet' passHref>
<NavDropdown.Item>wallet</NavDropdown.Item>
2021-05-05 18:13:14 +00:00
</Link>
2021-05-06 21:15:22 +00:00
<div>
<NavDropdown.Divider />
<Link href='/recent' passHref>
<NavDropdown.Item>recent</NavDropdown.Item>
</Link>
<Link href='/post' passHref>
<NavDropdown.Item>post</NavDropdown.Item>
</Link>
<NavDropdown.Item href='https://bitcoinerjobs.co' target='_blank'>jobs</NavDropdown.Item>
</div>
<NavDropdown.Divider />
2021-05-05 18:13:14 +00:00
<NavDropdown.Item onClick={signOut}>logout</NavDropdown.Item>
</NavDropdown>
<Nav.Item>
2021-05-06 21:15:22 +00:00
<Link href='/wallet' passHref>
<Nav.Link className='text-success px-0'>[0,0]</Nav.Link>
2021-05-05 18:13:14 +00:00
</Link>
</Nav.Item>
</div>
2021-04-12 18:05:09 +00:00
)
} else {
2021-05-05 18:13:14 +00:00
return path !== '/login' && <Button href='/login' onClick={signIn}>login</Button>
2021-04-12 18:05:09 +00:00
}
2021-03-25 19:29:24 +00:00
}
return (
2021-04-12 18:05:09 +00:00
<>
2021-04-28 16:30:02 +00:00
<Container className='px-sm-0'>
<Navbar className={styles.navbar}>
2021-05-05 18:13:14 +00:00
<Nav className='w-100 justify-content-between flex-wrap align-items-center' activeKey={path}>
2021-04-28 16:30:02 +00:00
<Link href='/' passHref>
2021-05-06 21:15:22 +00:00
<Navbar.Brand className={`${styles.brand} d-none d-sm-block`}>STACKER NEWS</Navbar.Brand>
2021-04-28 21:30:32 +00:00
</Link>
<Link href='/' passHref>
2021-05-06 21:15:22 +00:00
<Navbar.Brand className={`${styles.brand} d-block d-sm-none`}>SN</Navbar.Brand>
2021-04-28 16:30:02 +00:00
</Link>
2021-05-06 21:15:22 +00:00
<Nav.Item className='d-md-flex d-none'>
2021-04-14 00:57:32 +00:00
<Link href='/recent' passHref>
2021-04-28 16:30:02 +00:00
<Nav.Link className={styles.navLink}>recent</Nav.Link>
2021-04-14 00:57:32 +00:00
</Link>
</Nav.Item>
2021-05-06 21:15:22 +00:00
<Nav.Item className='d-md-flex d-none'>
2021-04-14 00:57:32 +00:00
<Link href='/post' passHref>
2021-04-28 16:30:02 +00:00
<Nav.Link className={styles.navLink}>post</Nav.Link>
2021-04-14 00:57:32 +00:00
</Link>
</Nav.Item>
2021-05-06 21:15:22 +00:00
<Nav.Item className='d-md-flex d-none'>
2021-04-28 16:30:02 +00:00
<Nav.Link href='https://bitcoinerjobs.co' target='_blank' className={styles.navLink}>jobs</Nav.Link>
</Nav.Item>
2021-04-28 19:30:14 +00:00
<Nav.Item style={{ fontFamily: 'monospace', opacity: '.5' }}>
<Price />
</Nav.Item>
2021-04-14 00:57:32 +00:00
<Corner />
</Nav>
2021-04-28 16:30:02 +00:00
</Navbar>
</Container>
2021-04-12 18:05:09 +00:00
</>
2021-03-25 19:29:24 +00:00
)
}