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

settings users last seen

This commit is contained in:
Fedor Katurov 2020-04-14 12:11:04 +07:00
parent 27fad84f9e
commit bfa61d3987
3 changed files with 18 additions and 3 deletions

View file

@ -1,18 +1,20 @@
import React, { FC, useEffect } from 'react'; import React, { FC, useEffect } from 'react';
import { RouteComponentProps } from 'react-router'; import { RouteComponentProps } from 'react-router';
import * as NODE_ACTIONS from '~/redux/node/actions';
import { selectNode } from '~/redux/node/selectors'; import { selectNode } from '~/redux/node/selectors';
import { selectUser } from '~/redux/auth/selectors'; import { selectUser } from '~/redux/auth/selectors';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { NodeComments } from '~/components/node/NodeComments'; import { NodeComments } from '~/components/node/NodeComments';
import styles from './styles.scss'; import styles from './styles.scss';
import { CommentForm } from '~/components/node/CommentForm';
import { Group } from '~/components/containers/Group'; import { Group } from '~/components/containers/Group';
import boris from '~/sprites/boris_robot.svg'; import boris from '~/sprites/boris_robot.svg';
import { NodeNoComments } from '~/components/node/NodeNoComments'; import { NodeNoComments } from '~/components/node/NodeNoComments';
import { getRandomPhrase } from '~/constants/phrases'; import { getRandomPhrase } from '~/constants/phrases';
import { NodeCommentForm } from '~/components/node/NodeCommentForm'; 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 => ({ const mapStateToProps = state => ({
node: selectNode(state), node: selectNode(state),
user: selectUser(state), user: selectUser(state),
@ -23,6 +25,7 @@ const mapDispatchToProps = {
nodeLockComment: NODE_ACTIONS.nodeLockComment, nodeLockComment: NODE_ACTIONS.nodeLockComment,
nodeEditComment: NODE_ACTIONS.nodeEditComment, nodeEditComment: NODE_ACTIONS.nodeEditComment,
nodeLoadMoreComments: NODE_ACTIONS.nodeLoadMoreComments, nodeLoadMoreComments: NODE_ACTIONS.nodeLoadMoreComments,
authSetUser: AUTH_ACTIONS.authSetUser,
}; };
type IProps = ReturnType<typeof mapStateToProps> & type IProps = ReturnType<typeof mapStateToProps> &
@ -34,14 +37,24 @@ const id = 696;
const BorisLayoutUnconnected: FC<IProps> = ({ const BorisLayoutUnconnected: FC<IProps> = ({
node: { is_loading, is_loading_comments, comments = [], comment_data, comment_count }, node: { is_loading, is_loading_comments, comments = [], comment_data, comment_count },
user, user,
user: { is_user }, user: { is_user, last_seen_boris },
nodeLoadNode, nodeLoadNode,
nodeLockComment, nodeLockComment,
nodeEditComment, nodeEditComment,
nodeLoadMoreComments, nodeLoadMoreComments,
authSetUser,
}) => { }) => {
const title = getRandomPhrase('BORIS_TITLE'); 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(() => { useEffect(() => {
if (is_loading) return; if (is_loading) return;
nodeLoadNode(id, 'DESC'); nodeLoadNode(id, 'DESC');

View file

@ -62,6 +62,7 @@ export const EMPTY_USER: IUser = {
last_seen: null, last_seen: null,
last_seen_messages: null, last_seen_messages: null,
last_seen_boris: null,
}; };
export interface IApiUser { export interface IApiUser {

View file

@ -18,6 +18,7 @@ export interface IUser {
last_seen: string; last_seen: string;
last_seen_messages: string; last_seen_messages: string;
last_seen_boris: string;
is_activated: boolean; is_activated: boolean;
is_user: boolean; is_user: boolean;