Don't use very slow dayjs formatter on timestamp tooltips
This commit is contained in:
parent
5d8f5d41fc
commit
998929dae2
|
@ -233,7 +233,7 @@ export function ContractDetails(props: {
|
||||||
<ClockIcon className="h-5 w-5" />
|
<ClockIcon className="h-5 w-5" />
|
||||||
<DateTimeTooltip
|
<DateTimeTooltip
|
||||||
text="Market resolved:"
|
text="Market resolved:"
|
||||||
time={dayjs(contract.resolutionTime)}
|
time={contract.resolutionTime}
|
||||||
>
|
>
|
||||||
{resolvedDate}
|
{resolvedDate}
|
||||||
</DateTimeTooltip>
|
</DateTimeTooltip>
|
||||||
|
@ -322,7 +322,7 @@ function EditableCloseDate(props: {
|
||||||
) : (
|
) : (
|
||||||
<DateTimeTooltip
|
<DateTimeTooltip
|
||||||
text={closeTime > Date.now() ? 'Trading ends:' : 'Trading ended:'}
|
text={closeTime > Date.now() ? 'Trading ends:' : 'Trading ended:'}
|
||||||
time={dayJsCloseTime}
|
time={closeTime}
|
||||||
>
|
>
|
||||||
{isSameYear
|
{isSameYear
|
||||||
? dayJsCloseTime.format('MMM D')
|
? dayJsCloseTime.format('MMM D')
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
import dayjs, { Dayjs } from 'dayjs'
|
|
||||||
import utc from 'dayjs/plugin/utc'
|
|
||||||
import timezone from 'dayjs/plugin/timezone'
|
|
||||||
import advanced from 'dayjs/plugin/advancedFormat'
|
|
||||||
import { Tooltip } from './tooltip'
|
import { Tooltip } from './tooltip'
|
||||||
|
|
||||||
dayjs.extend(utc)
|
const FORMATTER = new Intl.DateTimeFormat('default', {
|
||||||
dayjs.extend(timezone)
|
dateStyle: 'medium',
|
||||||
dayjs.extend(advanced)
|
timeStyle: 'long',
|
||||||
|
})
|
||||||
|
|
||||||
export function DateTimeTooltip(props: {
|
export function DateTimeTooltip(props: {
|
||||||
time: Dayjs
|
time: number
|
||||||
text?: string
|
text?: string
|
||||||
className?: string
|
className?: string
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
|
@ -17,7 +14,7 @@ export function DateTimeTooltip(props: {
|
||||||
}) {
|
}) {
|
||||||
const { className, time, text, noTap } = props
|
const { className, time, text, noTap } = props
|
||||||
|
|
||||||
const formattedTime = time.format('MMM DD, YYYY hh:mm a z')
|
const formattedTime = FORMATTER.format(time)
|
||||||
const toolTip = text ? `${text} ${formattedTime}` : formattedTime
|
const toolTip = text ? `${text} ${formattedTime}` : formattedTime
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -7,7 +7,6 @@ import { fromNow } from 'web/lib/util/time'
|
||||||
import { ToastClipboard } from 'web/components/toast-clipboard'
|
import { ToastClipboard } from 'web/components/toast-clipboard'
|
||||||
import { LinkIcon } from '@heroicons/react/outline'
|
import { LinkIcon } from '@heroicons/react/outline'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import dayjs from 'dayjs'
|
|
||||||
|
|
||||||
export function CopyLinkDateTimeComponent(props: {
|
export function CopyLinkDateTimeComponent(props: {
|
||||||
prefix: string
|
prefix: string
|
||||||
|
@ -18,7 +17,6 @@ export function CopyLinkDateTimeComponent(props: {
|
||||||
}) {
|
}) {
|
||||||
const { prefix, slug, elementId, createdTime, className } = props
|
const { prefix, slug, elementId, createdTime, className } = props
|
||||||
const [showToast, setShowToast] = useState(false)
|
const [showToast, setShowToast] = useState(false)
|
||||||
const time = dayjs(createdTime)
|
|
||||||
|
|
||||||
function copyLinkToComment(
|
function copyLinkToComment(
|
||||||
event: React.MouseEvent<HTMLAnchorElement, MouseEvent>
|
event: React.MouseEvent<HTMLAnchorElement, MouseEvent>
|
||||||
|
@ -32,7 +30,7 @@ export function CopyLinkDateTimeComponent(props: {
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className={clsx('inline', className)}>
|
<div className={clsx('inline', className)}>
|
||||||
<DateTimeTooltip time={time} noTap>
|
<DateTimeTooltip time={createdTime} noTap>
|
||||||
<Link href={`/${prefix}/${slug}#${elementId}`} passHref={true}>
|
<Link href={`/${prefix}/${slug}#${elementId}`} passHref={true}>
|
||||||
<a
|
<a
|
||||||
onClick={(event) => copyLinkToComment(event)}
|
onClick={(event) => copyLinkToComment(event)}
|
||||||
|
|
|
@ -8,7 +8,7 @@ export function RelativeTimestamp(props: { time: number }) {
|
||||||
return (
|
return (
|
||||||
<DateTimeTooltip
|
<DateTimeTooltip
|
||||||
className="ml-1 whitespace-nowrap text-gray-400"
|
className="ml-1 whitespace-nowrap text-gray-400"
|
||||||
time={dayJsTime}
|
time={time}
|
||||||
>
|
>
|
||||||
{dayJsTime.fromNow()}
|
{dayJsTime.fromNow()}
|
||||||
</DateTimeTooltip>
|
</DateTimeTooltip>
|
||||||
|
|
|
@ -188,7 +188,7 @@ function Section(props: {
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{endTime && (
|
{endTime && (
|
||||||
<DateTimeTooltip time={endTime} text="Ends">
|
<DateTimeTooltip time={endTime.valueOf()} text="Ends">
|
||||||
<span className="flex items-center gap-1">
|
<span className="flex items-center gap-1">
|
||||||
<ClockIcon className="h-4" />
|
<ClockIcon className="h-4" />
|
||||||
{endTime.format('MMM D')}
|
{endTime.format('MMM D')}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user