diff --git a/src/containers/node/BorisLayout/index.tsx b/src/containers/node/BorisLayout/index.tsx index 791605b9..b66a30ee 100644 --- a/src/containers/node/BorisLayout/index.tsx +++ b/src/containers/node/BorisLayout/index.tsx @@ -1,18 +1,20 @@ import React, { FC, useEffect } from 'react'; import { RouteComponentProps } from 'react-router'; -import * as NODE_ACTIONS from '~/redux/node/actions'; import { selectNode } from '~/redux/node/selectors'; import { selectUser } from '~/redux/auth/selectors'; import { connect } from 'react-redux'; import { NodeComments } from '~/components/node/NodeComments'; import styles from './styles.scss'; -import { CommentForm } from '~/components/node/CommentForm'; import { Group } from '~/components/containers/Group'; import boris from '~/sprites/boris_robot.svg'; import { NodeNoComments } from '~/components/node/NodeNoComments'; import { getRandomPhrase } from '~/constants/phrases'; import { NodeCommentForm } from '~/components/node/NodeCommentForm'; +import * as NODE_ACTIONS from '~/redux/node/actions'; +import * as AUTH_ACTIONS from '~/redux/auth/actions'; +import isBefore from 'date-fns/isBefore'; + const mapStateToProps = state => ({ node: selectNode(state), user: selectUser(state), @@ -23,6 +25,7 @@ const mapDispatchToProps = { nodeLockComment: NODE_ACTIONS.nodeLockComment, nodeEditComment: NODE_ACTIONS.nodeEditComment, nodeLoadMoreComments: NODE_ACTIONS.nodeLoadMoreComments, + authSetUser: AUTH_ACTIONS.authSetUser, }; type IProps = ReturnType & @@ -34,14 +37,24 @@ const id = 696; const BorisLayoutUnconnected: FC = ({ node: { is_loading, is_loading_comments, comments = [], comment_data, comment_count }, user, - user: { is_user }, + user: { is_user, last_seen_boris }, nodeLoadNode, nodeLockComment, nodeEditComment, nodeLoadMoreComments, + authSetUser, }) => { const title = getRandomPhrase('BORIS_TITLE'); + useEffect(() => { + const last_comment = comments[0]; + if (!last_comment) return; + if (last_seen_boris && !isBefore(new Date(last_seen_boris), new Date(last_comment.created_at))) + return; + + authSetUser({ last_seen_boris: last_comment.created_at }); + }, [comments, last_seen_boris]); + useEffect(() => { if (is_loading) return; nodeLoadNode(id, 'DESC'); diff --git a/src/redux/auth/constants.ts b/src/redux/auth/constants.ts index e1b0980f..5f763ede 100644 --- a/src/redux/auth/constants.ts +++ b/src/redux/auth/constants.ts @@ -62,6 +62,7 @@ export const EMPTY_USER: IUser = { last_seen: null, last_seen_messages: null, + last_seen_boris: null, }; export interface IApiUser { diff --git a/src/redux/auth/types.ts b/src/redux/auth/types.ts index c3d049be..c44616cd 100644 --- a/src/redux/auth/types.ts +++ b/src/redux/auth/types.ts @@ -18,6 +18,7 @@ export interface IUser { last_seen: string; last_seen_messages: string; + last_seen_boris: string; is_activated: boolean; is_user: boolean;