2022-03-30 23:01:24 -04:00
|
|
|
import { Badge, Tooltip } from "@geist-ui/core";
|
|
|
|
import { timeAgo } from "@lib/time-ago";
|
|
|
|
import { useMemo, useState, useEffect } from "react";
|
|
|
|
|
|
|
|
const CreatedAgoBadge = ({ createdAt }: {
|
|
|
|
createdAt: string | Date;
|
|
|
|
}) => {
|
|
|
|
const createdDate = useMemo(() => new Date(createdAt), [createdAt])
|
|
|
|
const [time, setTimeAgo] = useState(timeAgo(createdDate))
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const interval = setInterval(() => {
|
|
|
|
setTimeAgo(timeAgo(createdDate))
|
|
|
|
}, 1000)
|
|
|
|
return () => clearInterval(interval)
|
|
|
|
}, [createdDate])
|
|
|
|
|
|
|
|
const formattedTime = `${createdDate.toLocaleDateString()} ${createdDate.toLocaleTimeString()}`
|
2022-04-02 01:55:27 -04:00
|
|
|
return (<Badge type="secondary"> <Tooltip hideArrow text={formattedTime}>Created {time}</Tooltip></Badge>)
|
2022-03-30 23:01:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default CreatedAgoBadge
|