Skip to content

Commit

Permalink
use memo for notification seen state
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-funk committed Oct 25, 2023
1 parent cd33c2b commit f182afb
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cn from "classnames";
import React, { FunctionComponent } from "react";
import React, { FunctionComponent, useMemo } from "react";
import { graphql } from "react-relay";

import { getURLWithCommentID } from "coral-framework/helpers";
Expand All @@ -19,16 +19,18 @@ const NotificationContainer: FunctionComponent<Props> = ({
notification: { title, body, comment, createdAt },
viewer,
}) => {
if (!viewer) {
return null;
}
const seen = useMemo(() => {
if (!viewer) {
return false;
}

const createdAtDate = new Date(createdAt);
const lastSeenDate = viewer.lastSeenNotificationDate
? new Date(viewer.lastSeenNotificationDate)
: new Date(0);
const createdAtDate = new Date(createdAt);
const lastSeenDate = viewer.lastSeenNotificationDate
? new Date(viewer.lastSeenNotificationDate)
: new Date(0);

const seen = createdAtDate.getTime() <= lastSeenDate.getTime();
return createdAtDate.getTime() <= lastSeenDate.getTime();
}, [createdAt, viewer]);

const commentURL = comment
? getURLWithCommentID(comment.story.url, comment.id)
Expand All @@ -44,7 +46,6 @@ const NotificationContainer: FunctionComponent<Props> = ({
{title && <div className={cn(styles.title)}>{title}</div>}
{body && <div className={cn(styles.body)}>{body}</div>}
{comment && <a href={commentURL}>{commentURL}</a>}
{`seen: ${seen}`}
</div>
);
};
Expand Down

0 comments on commit f182afb

Please sign in to comment.