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'))
|
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 }) {
|
export default function Time({ date }: { date: string }) {
|
||||||
const dateNew = new Date(date)
|
const dateNew = new Date(date)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LazyDate>
|
<LazyDate fallback={<TimeMarkup date={dateNew} />}>
|
||||||
{({ format, formatDistance }) => (
|
{({ format, formatDistance }) => (
|
||||||
<time
|
<TimeMarkup
|
||||||
title={format(dateNew, 'yyyy/MM/dd HH:mm')}
|
date={dateNew}
|
||||||
dateTime={dateNew.toISOString()}
|
format={format}
|
||||||
>
|
formatDistance={formatDistance}
|
||||||
{formatDistance(dateNew, Date.now(), { addSuffix: true })}
|
/>
|
||||||
</time>
|
|
||||||
)}
|
)}
|
||||||
</LazyDate>
|
</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 shortid from 'shortid'
|
||||||
import Helmet from 'react-helmet'
|
import Helmet from 'react-helmet'
|
||||||
import { Author } from '../@types/Site'
|
import { Author } from '../@types/Site'
|
||||||
@ -7,7 +8,9 @@ import Qr from '../components/atoms/Qr'
|
|||||||
import Icon from '../components/atoms/Icon'
|
import Icon from '../components/atoms/Icon'
|
||||||
import styles from './thanks.module.scss'
|
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 }) => (
|
const Coin = ({ address, author }: { address: string; author: Author }) => (
|
||||||
<div className={styles.coin}>
|
<div className={styles.coin}>
|
||||||
@ -29,7 +32,6 @@ export default function Thanks() {
|
|||||||
const coins = Object.keys(author).filter(
|
const coins = Object.keys(author).filter(
|
||||||
key => key === 'bitcoin' || key === 'ether'
|
key => key === 'bitcoin' || key === 'ether'
|
||||||
)
|
)
|
||||||
const isSSR = typeof window === 'undefined'
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -43,26 +45,22 @@ export default function Thanks() {
|
|||||||
<header>
|
<header>
|
||||||
<h1 className={styles.title}>Say Thanks</h1>
|
<h1 className={styles.title}>Say Thanks</h1>
|
||||||
</header>
|
</header>
|
||||||
{!isSSR && (
|
|
||||||
<Suspense fallback={<div className={styles.loading}>Loading...</div>}>
|
|
||||||
<Web3Donation address={author.ether} />
|
|
||||||
|
|
||||||
<div className={styles.coins}>
|
<Web3Donation
|
||||||
<header>
|
fallback={<div className={styles.loading}>Loading...</div>}
|
||||||
<h4>Any other wallets</h4>
|
address={author.ether}
|
||||||
<p>Send Bitcoin or Ether from any wallet.</p>
|
/>
|
||||||
</header>
|
|
||||||
|
|
||||||
{coins.map((address: string) => (
|
<div className={styles.coins}>
|
||||||
<Coin
|
<header>
|
||||||
key={shortid.generate()}
|
<h4>Any other wallets</h4>
|
||||||
address={address}
|
<p>Send Bitcoin or Ether from any wallet.</p>
|
||||||
author={author}
|
</header>
|
||||||
/>
|
|
||||||
))}
|
{coins.map((address: string) => (
|
||||||
</div>
|
<Coin key={shortid.generate()} address={address} author={author} />
|
||||||
</Suspense>
|
))}
|
||||||
)}
|
</div>
|
||||||
</article>
|
</article>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user