mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
32 lines
698 B
TypeScript
32 lines
698 B
TypeScript
import React, { FC, memo, useMemo } from 'react';
|
||
|
||
import { formatDistance } from 'date-fns';
|
||
import ru from 'date-fns/locale/ru';
|
||
|
||
import styles from './styles.module.scss';
|
||
|
||
interface CommentDistanceProps {
|
||
firstDate?: Date;
|
||
secondDate?: Date;
|
||
}
|
||
|
||
const CommentDistance: FC<CommentDistanceProps> = memo(({ firstDate, secondDate }) => {
|
||
const distance = useMemo(() => {
|
||
if (!firstDate || !secondDate) {
|
||
return undefined;
|
||
}
|
||
|
||
return formatDistance(secondDate, firstDate, {
|
||
locale: ru,
|
||
addSuffix: false,
|
||
});
|
||
}, []);
|
||
|
||
if (!distance) {
|
||
return null;
|
||
}
|
||
|
||
return <div className={styles.bar}>прошло {distance}</div>;
|
||
});
|
||
|
||
export { CommentDistance };
|