mirror of
https://github.com/kremalicious/blog.git
synced 2024-12-22 09:13:35 +01:00
fallbacks
This commit is contained in:
parent
df9a850f92
commit
8cd629a33b
@ -3,18 +3,38 @@ import loadable from '@loadable/component'
|
||||
|
||||
const LazyDate = loadable.lib(() => import('date-fns'))
|
||||
|
||||
function TimeMarkup({
|
||||
date,
|
||||
format,
|
||||
formatDistance
|
||||
}: {
|
||||
date: Date
|
||||
format?: any
|
||||
formatDistance?: any
|
||||
}) {
|
||||
const dateIso = date.toISOString()
|
||||
|
||||
return (
|
||||
<time
|
||||
title={format ? format(date, 'yyyy/MM/dd HH:mm') : dateIso}
|
||||
dateTime={dateIso}
|
||||
>
|
||||
{format ? formatDistance(date, Date.now(), { addSuffix: true }) : dateIso}
|
||||
</time>
|
||||
)
|
||||
}
|
||||
|
||||
export default function Time({ date }: { date: string }) {
|
||||
const dateNew = new Date(date)
|
||||
|
||||
return (
|
||||
<LazyDate>
|
||||
<LazyDate fallback={<TimeMarkup date={dateNew} />}>
|
||||
{({ format, formatDistance }) => (
|
||||
<time
|
||||
title={format(dateNew, 'yyyy/MM/dd HH:mm')}
|
||||
dateTime={dateNew.toISOString()}
|
||||
>
|
||||
{formatDistance(dateNew, Date.now(), { addSuffix: true })}
|
||||
</time>
|
||||
<TimeMarkup
|
||||
date={dateNew}
|
||||
format={format}
|
||||
formatDistance={formatDistance}
|
||||
/>
|
||||
)}
|
||||
</LazyDate>
|
||||
)
|
||||
|
@ -1,4 +1,5 @@
|
||||
import React, { lazy, Suspense } from 'react'
|
||||
import React from 'react'
|
||||
import loadable from '@loadable/component'
|
||||
import shortid from 'shortid'
|
||||
import Helmet from 'react-helmet'
|
||||
import { Author } from '../@types/Site'
|
||||
@ -7,7 +8,9 @@ import Qr from '../components/atoms/Qr'
|
||||
import Icon from '../components/atoms/Icon'
|
||||
import styles from './thanks.module.scss'
|
||||
|
||||
const Web3Donation = lazy(() => import('../components/molecules/Web3Donation'))
|
||||
const Web3Donation = loadable(() =>
|
||||
import('../components/molecules/Web3Donation')
|
||||
)
|
||||
|
||||
const Coin = ({ address, author }: { address: string; author: Author }) => (
|
||||
<div className={styles.coin}>
|
||||
@ -29,7 +32,6 @@ export default function Thanks() {
|
||||
const coins = Object.keys(author).filter(
|
||||
key => key === 'bitcoin' || key === 'ether'
|
||||
)
|
||||
const isSSR = typeof window === 'undefined'
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -43,26 +45,22 @@ export default function Thanks() {
|
||||
<header>
|
||||
<h1 className={styles.title}>Say Thanks</h1>
|
||||
</header>
|
||||
{!isSSR && (
|
||||
<Suspense fallback={<div className={styles.loading}>Loading...</div>}>
|
||||
<Web3Donation address={author.ether} />
|
||||
|
||||
<div className={styles.coins}>
|
||||
<header>
|
||||
<h4>Any other wallets</h4>
|
||||
<p>Send Bitcoin or Ether from any wallet.</p>
|
||||
</header>
|
||||
<Web3Donation
|
||||
fallback={<div className={styles.loading}>Loading...</div>}
|
||||
address={author.ether}
|
||||
/>
|
||||
|
||||
{coins.map((address: string) => (
|
||||
<Coin
|
||||
key={shortid.generate()}
|
||||
address={address}
|
||||
author={author}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</Suspense>
|
||||
)}
|
||||
<div className={styles.coins}>
|
||||
<header>
|
||||
<h4>Any other wallets</h4>
|
||||
<p>Send Bitcoin or Ether from any wallet.</p>
|
||||
</header>
|
||||
|
||||
{coins.map((address: string) => (
|
||||
<Coin key={shortid.generate()} address={address} author={author} />
|
||||
))}
|
||||
</div>
|
||||
</article>
|
||||
</>
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user