import React, { FC, useEffect } from 'react'; import { selectNode, selectNodeComments } from '~/redux/node/selectors'; import { selectUser } from '~/redux/auth/selectors'; import { useDispatch } from 'react-redux'; import { NodeComments } from '~/components/node/NodeComments'; import styles from './styles.module.scss'; import { Group } from '~/components/containers/Group'; import boris from '~/sprites/boris_robot.svg'; import { NodeNoComments } from '~/components/node/NodeNoComments'; import { useRandomPhrase } from '~/constants/phrases'; import { NodeCommentForm } from '~/components/node/NodeCommentForm'; import isBefore from 'date-fns/isBefore'; import { Card } from '~/components/containers/Card'; import { Footer } from '~/components/main/Footer'; import { Sticky } from '~/components/containers/Sticky'; import { BorisStats } from '~/components/boris/BorisStats'; import { useShallowSelect } from '~/utils/hooks/useShallowSelect'; import { selectBorisStats } from '~/redux/boris/selectors'; import { authSetUser } from '~/redux/auth/actions'; import { nodeLoadNode } from '~/redux/node/actions'; import { borisLoadStats } from '~/redux/boris/actions'; type IProps = {}; const BorisLayout: FC = () => { const title = useRandomPhrase('BORIS_TITLE'); const dispatch = useDispatch(); const node = useShallowSelect(selectNode); const user = useShallowSelect(selectUser); const stats = useShallowSelect(selectBorisStats); const comments = useShallowSelect(selectNodeComments); useEffect(() => { const last_comment = comments[0]; if (!last_comment) return; if ( user.last_seen_boris && !isBefore(new Date(user.last_seen_boris), new Date(last_comment.created_at)) ) return; dispatch(authSetUser({ last_seen_boris: last_comment.created_at })); }, [user.last_seen_boris, dispatch, comments]); useEffect(() => { if (node.is_loading) return; dispatch(nodeLoadNode(696, 'DESC')); }, [dispatch]); useEffect(() => { dispatch(borisLoadStats()); }, [dispatch]); return (
{title}
Борис
{user.is_user && } {node.is_loading_comments ? ( ) : ( )}
); }; export { BorisLayout };