2022-05-05 22:30:30 +00:00
|
|
|
import { DateTimeTooltip } from './datetime-tooltip'
|
2022-10-05 23:43:51 +00:00
|
|
|
import React, { useEffect, useState } from 'react'
|
2022-08-31 20:35:34 +00:00
|
|
|
import { fromNow } from 'web/lib/util/time'
|
2022-05-05 22:30:30 +00:00
|
|
|
|
|
|
|
export function RelativeTimestamp(props: { time: number }) {
|
|
|
|
const { time } = props
|
2022-10-05 23:43:51 +00:00
|
|
|
const [isClient, setIsClient] = useState(false)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
// Only render on client to prevent difference from server.
|
|
|
|
setIsClient(true)
|
|
|
|
}, [])
|
|
|
|
|
2022-05-05 22:30:30 +00:00
|
|
|
return (
|
2022-08-13 00:48:41 +00:00
|
|
|
<DateTimeTooltip
|
|
|
|
className="ml-1 whitespace-nowrap text-gray-400"
|
2022-08-27 20:46:35 +00:00
|
|
|
time={time}
|
2022-08-13 00:48:41 +00:00
|
|
|
>
|
2022-10-05 23:43:51 +00:00
|
|
|
{isClient ? fromNow(time) : ''}
|
2022-05-05 22:30:30 +00:00
|
|
|
</DateTimeTooltip>
|
|
|
|
)
|
|
|
|
}
|