-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathCommentsAction.jsx
35 lines (28 loc) · 1.05 KB
/
CommentsAction.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { useNavigate } from 'react-router-dom';
import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import CommentsIcon from 'components/icons/CommentsIcon';
import { questionSelectors } from 'features/questions/questionsSlice';
import { theme } from 'app/theme';
import { TheQuestionAction } from './TheQuestionAction';
export const CommentsAction = ({ questionId }) => {
const { REACT_APP_FEATURE_COMMENTARIES } = process.env;
const navigate = useNavigate();
const question = useSelector((state) => questionSelectors.selectById(state, questionId));
const handleOpenComments = () => {
navigate(`/question/${question._id}#scroll`);
};
if (!REACT_APP_FEATURE_COMMENTARIES) return null;
return (
<TheQuestionAction
icon={<CommentsIcon />}
onClick={handleOpenComments}
color={theme.colors.primary.main}
>
{question.commentsCount > 0 ? question.commentsCount : 'Обсуждение'}
</TheQuestionAction>
);
};
CommentsAction.propTypes = {
questionId: PropTypes.string.isRequired,
};