mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
added months passed to comments
This commit is contained in:
parent
e9a1a624fd
commit
3dfd886570
7 changed files with 111 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
|||
import { isAfter, isValid, parseISO } from 'date-fns';
|
||||
import { differenceInDays, isAfter, isValid, parseISO } from 'date-fns';
|
||||
|
||||
import { IComment, ICommentGroup } from '~/types';
|
||||
import { curry, insert, nth, path, remove } from '~/utils/ramda';
|
||||
|
@ -22,6 +22,21 @@ const compareCommentDates = (commentDateValue?: string, lastSeenDateValue?: stri
|
|||
return isAfter(commentDate, lastSeenDate);
|
||||
};
|
||||
|
||||
const getCommentDistance = (firstDate?: string, secondDate?: string) => {
|
||||
try {
|
||||
if (!firstDate || !secondDate) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const first = parseISO(firstDate);
|
||||
const second = parseISO(secondDate);
|
||||
|
||||
return differenceInDays(second, first);
|
||||
} catch (e) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
export const groupCommentsByUser = (lastSeen?: string) => (
|
||||
grouppedComments: ICommentGroup[],
|
||||
comment: IComment
|
||||
|
@ -40,6 +55,7 @@ export const groupCommentsByUser = (lastSeen?: string) => (
|
|||
{
|
||||
user: comment.user,
|
||||
comments: [comment],
|
||||
distancesInDays: [0],
|
||||
ids: [comment.id],
|
||||
hasNew: compareCommentDates(comment.created_at, lastSeen),
|
||||
},
|
||||
|
@ -49,6 +65,13 @@ export const groupCommentsByUser = (lastSeen?: string) => (
|
|||
...grouppedComments.slice(0, grouppedComments.length - 1),
|
||||
{
|
||||
...last,
|
||||
distancesInDays: [
|
||||
...last.distancesInDays,
|
||||
getCommentDistance(
|
||||
comment?.created_at,
|
||||
last.comments[last.comments.length - 1]?.created_at
|
||||
),
|
||||
],
|
||||
comments: [...last.comments, comment],
|
||||
ids: [...last.ids, comment.id],
|
||||
hasNew: last.hasNew || compareCommentDates(comment.created_at, lastSeen),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue