preload font, only show header items when they're done loading
This commit is contained in:
parent
eb02664084
commit
749b49c313
@ -23,6 +23,7 @@ export default function Header () {
|
|||||||
const [session, loading] = useSession()
|
const [session, loading] = useSession()
|
||||||
const [sort, setSort] = useState('recent')
|
const [sort, setSort] = useState('recent')
|
||||||
const [within, setWithin] = useState()
|
const [within, setWithin] = useState()
|
||||||
|
const [priceReady, setPriceReady] = useState()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSort(localStorage.getItem('sort') || 'recent')
|
setSort(localStorage.getItem('sort') || 'recent')
|
||||||
@ -127,6 +128,8 @@ export default function Header () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const visible = ((session && me) || (!session && !loading)) && priceReady ? 'visible' : 'invisible'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Container className='px-sm-0'>
|
<Container className='px-sm-0'>
|
||||||
@ -141,13 +144,13 @@ export default function Header () {
|
|||||||
<Link href='/' passHref>
|
<Link href='/' passHref>
|
||||||
<Navbar.Brand className={`${styles.brand} d-block d-sm-none`}>SN</Navbar.Brand>
|
<Navbar.Brand className={`${styles.brand} d-block d-sm-none`}>SN</Navbar.Brand>
|
||||||
</Link>
|
</Link>
|
||||||
<Nav.Item className='d-md-flex d-none nav-dropdown-toggle'>
|
<Nav.Item className={`d-md-flex d-none nav-dropdown-toggle ${visible}`}>
|
||||||
<SplitButton
|
<SplitButton
|
||||||
title={
|
title={
|
||||||
<Link href={sortLink} passHref>
|
<Link href={sortLink} passHref>
|
||||||
<Nav.Link className={styles.navLink}>{sort}</Nav.Link>
|
<Nav.Link className={styles.navLink}>{sort}</Nav.Link>
|
||||||
</Link>
|
</Link>
|
||||||
}
|
}
|
||||||
key={`/${sort}`}
|
key={`/${sort}`}
|
||||||
id='recent-top-button'
|
id='recent-top-button'
|
||||||
variant='link'
|
variant='link'
|
||||||
@ -158,7 +161,7 @@ export default function Header () {
|
|||||||
</Link>
|
</Link>
|
||||||
</SplitButton>
|
</SplitButton>
|
||||||
</Nav.Item>
|
</Nav.Item>
|
||||||
<Nav.Item className='d-md-flex d-none'>
|
<Nav.Item className={`d-md-flex d-none ${visible}`}>
|
||||||
{me
|
{me
|
||||||
? (
|
? (
|
||||||
<Link href='/post' passHref>
|
<Link href='/post' passHref>
|
||||||
@ -167,13 +170,15 @@ export default function Header () {
|
|||||||
)
|
)
|
||||||
: <Nav.Link className={styles.navLink} onClick={signIn}>post</Nav.Link>}
|
: <Nav.Link className={styles.navLink} onClick={signIn}>post</Nav.Link>}
|
||||||
</Nav.Item>
|
</Nav.Item>
|
||||||
<Nav.Item className='d-md-flex d-none'>
|
<Nav.Item className={`d-md-flex d-none ${visible}`}>
|
||||||
<Nav.Link href='https://bitcoinerjobs.co' target='_blank' className={styles.navLink}>jobs</Nav.Link>
|
<Nav.Link href='https://bitcoinerjobs.co' target='_blank' className={styles.navLink}>jobs</Nav.Link>
|
||||||
</Nav.Item>
|
</Nav.Item>
|
||||||
<Nav.Item className='text-monospace' style={{ opacity: '.5' }}>
|
<Nav.Item className={`text-monospace ${visible}`} style={{ opacity: '.5' }}>
|
||||||
<Price />
|
<Price onReady={() => setPriceReady(true)} />
|
||||||
</Nav.Item>
|
</Nav.Item>
|
||||||
<Corner />
|
<div className={visible}>
|
||||||
|
<Corner />
|
||||||
|
</div>
|
||||||
</Nav>
|
</Nav>
|
||||||
</Navbar>
|
</Navbar>
|
||||||
</Container>
|
</Container>
|
||||||
|
@ -23,4 +23,9 @@
|
|||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.easein {
|
||||||
|
transition-timing-function: ease;
|
||||||
|
transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ import useSWR from 'swr'
|
|||||||
|
|
||||||
const fetcher = url => fetch(url).then(res => res.json())
|
const fetcher = url => fetch(url).then(res => res.json())
|
||||||
|
|
||||||
export default function Price () {
|
export default function Price ({ onReady }) {
|
||||||
const [asSats, setAsSats] = useState(undefined)
|
const [asSats, setAsSats] = useState(undefined)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setAsSats(localStorage.getItem('asSats'))
|
setAsSats(localStorage.getItem('asSats'))
|
||||||
@ -17,6 +17,12 @@ export default function Price () {
|
|||||||
refreshInterval: 30000
|
refreshInterval: 30000
|
||||||
})
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (onReady) {
|
||||||
|
onReady()
|
||||||
|
}
|
||||||
|
}, [data])
|
||||||
|
|
||||||
if (!data || !data.data) return null
|
if (!data || !data.data) return null
|
||||||
|
|
||||||
const fixed = (n, f) => Number.parseFloat(n).toFixed(f)
|
const fixed = (n, f) => Number.parseFloat(n).toFixed(f)
|
||||||
@ -32,14 +38,14 @@ export default function Price () {
|
|||||||
|
|
||||||
if (asSats) {
|
if (asSats) {
|
||||||
return (
|
return (
|
||||||
<Button className='text-reset' onClick={handleClick} variant='link'>
|
<Button className='text-reset py-0' onClick={handleClick} variant='link'>
|
||||||
{fixed(100000000 / data.data.amount, 0) + ' sats/$'}
|
{fixed(100000000 / data.data.amount, 0) + ' sats/$'}
|
||||||
</Button>
|
</Button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button className='text-reset' onClick={handleClick} variant='link'>
|
<Button className='text-reset py-0' onClick={handleClick} variant='link'>
|
||||||
{'$' + fixed(data.data.amount, 2)}
|
{'$' + fixed(data.data.amount, 2)}
|
||||||
</Button>
|
</Button>
|
||||||
)
|
)
|
||||||
|
@ -4,9 +4,11 @@ class MyDocument extends Document {
|
|||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
<Html>
|
<Html>
|
||||||
<Head />
|
<Head>
|
||||||
|
<link rel='preload' href='/Lightningvolt-xoqm.ttf' as='font' type='font/ttf' crossOrigin='' />
|
||||||
|
</Head>
|
||||||
<body>
|
<body>
|
||||||
<script src='darkmode.js' />
|
<script src='darkmode.js' type='module' />
|
||||||
<Main />
|
<Main />
|
||||||
<NextScript />
|
<NextScript />
|
||||||
</body>
|
</body>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Insert this script in your index.html right after the <body> tag.
|
// Insert this script in your index.html right after the <body> tag.
|
||||||
// This will help to prevent a flash if dark mode is the default.
|
// This will help to prevent a flash if dark mode is the default.
|
||||||
export const COLORS = {
|
const COLORS = {
|
||||||
light: {
|
light: {
|
||||||
body: '#f5f5f5',
|
body: '#f5f5f5',
|
||||||
color: '#212529',
|
color: '#212529',
|
||||||
@ -45,7 +45,7 @@ export const handleThemeChange = (dark) => {
|
|||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
(function () {
|
(function () {
|
||||||
// Change these if you use something different in your hook.
|
// Change these if you use something different in your hook.
|
||||||
const storageKey = 'darkMode'
|
const storageKey = 'darkMode'
|
||||||
|
|
||||||
const preferDarkQuery = '(prefers-color-scheme: dark)'
|
const preferDarkQuery = '(prefers-color-scheme: dark)'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user