1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

added months passed to comments

This commit is contained in:
Fedor Katurov 2022-07-15 16:45:59 +07:00
parent e9a1a624fd
commit 3dfd886570
7 changed files with 111 additions and 9 deletions

View file

@ -0,0 +1,36 @@
import React, { FC, memo, useMemo } from 'react';
import { differenceInDays, 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;
}
if (differenceInDays(secondDate, firstDate) < 30) {
return undefined;
}
return formatDistance(secondDate, firstDate, {
locale: ru,
addSuffix: false,
});
}, []);
if (!distance) {
return null;
}
return <div className={styles.bar}>прошло {distance}</div>;
});
export { CommentDistance };