import React from 'react'; import cx from 'classnames'; import { isEmpty } from 'lodash'; import { pluralize, hightlightMentionedUserInComment } from '@/_helpers/utils'; import moment from 'moment'; import useRouter from '@/_hooks/use-router'; import Spinner from '@/_ui/Spinner'; const Content = ({ notifications, loading }) => { const router = useRouter(); const [selectedCommentId, setSelectedCommentId] = React.useState(router.query.commentId); React.useEffect(() => { if (router.query?.commentId) setSelectedCommentId(router.query?.commentId); else setSelectedCommentId(''); }, [router]); const getContent = () => { if (isEmpty(notifications)) return (

{loading ? : 'No messages to show'}

); return (
{notifications.map(({ comment, count }) => { return (
{ router.push({ // react router updates the url with the set basename resulting invalid url unless replaced pathname: window.location.pathname.replace(window.public_config?.SUB_PATH, '/'), search: `?threadId=${comment.thread.id}&commentId=${comment.id}`, }); }} key={comment.id} >
{`${comment.user?.firstName} ${comment.user?.lastName}`}{' '}
{moment(comment.createdAt).fromNow()}
{`${count - 1} replies`}
); })}
); }; // TODO: move filter to separate file return (
{!loading && (
Total {pluralize(notifications.length, 'comment')}
)}
{getContent()}
); }; export default Content;