From d42c1ca10a1acc7902672761d5933b64ee98f1f3 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 30 Jan 2023 11:00:02 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D0=95=D1=81=D0=BB=D0=B8=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D0=B7=D0=B0=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=8B=D1=82=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B9=D0=BA=D0=BD=D1=83=D1=82=D1=8C=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8=D0=B9,=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=B5=D0=B4=D0=B8=D1=82=D1=81=D1=8F=20=D0=BE?= =?UTF-8?q?=D0=BA=D0=BD=D0=BE,=20=D1=81=20=D0=BF=D1=80=D0=BE=D1=81=D1=8C?= =?UTF-8?q?=D0=B1=D0=BE=D0=B9=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/comments/CommentView.jsx | 26 ++++++++++++++----- .../question-actions/FavoritePopover.jsx | 8 +++++- .../FavoritePopoverContent.jsx | 9 +++++-- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/features/comments/CommentView.jsx b/src/features/comments/CommentView.jsx index eada9d8..5755add 100644 --- a/src/features/comments/CommentView.jsx +++ b/src/features/comments/CommentView.jsx @@ -2,11 +2,13 @@ import { Viewer } from '@toast-ui/react-editor'; import { useAuth } from 'common/context/Auth/useAuth'; import PropTypes from 'prop-types'; import styled from 'styled-components'; -import React from 'react'; +import React, { useState } from 'react'; import dayjs from 'dayjs'; import { HeartFilled, HeartOutlined } from '@ant-design/icons'; import { useDispatch, useSelector } from 'react-redux'; import { selectProfile } from 'features/profile/profileSlice'; +import FavoritePopoverContent from 'features/questions/questions-list/question-actions/FavoritePopoverContent'; +import { Popover } from 'antd'; import { CommentsActions } from './comment-actions/CommentsActions'; import { likeCommentById, unlikeCommentById } from './commentsSlice'; @@ -69,6 +71,10 @@ const StyledCommentActions = styled.div` export const CommentView = ({ comment, lastComment }) => { const Wrapper = lastComment ? StyledWrapper : React.Fragment; + const [open, setOpen] = useState(false); + + const text = 'что бы иметь возможность лайкать комментарии'; + const dispatch = useDispatch(); const { token } = useAuth(); @@ -80,11 +86,13 @@ export const CommentView = ({ comment, lastComment }) => { const userId = profile._id; const handleToggleLike = () => { - if (!commentLikes.includes(userId)) { - dispatch(likeCommentById({ commentId, userId })); - } else { - dispatch(unlikeCommentById({ commentId, userId })); - } + if (token) { + if (!commentLikes.includes(userId)) { + dispatch(likeCommentById({ commentId, userId })); + } else { + dispatch(unlikeCommentById({ commentId, userId })); + } + } else setOpen(!open); }; return ( @@ -110,7 +118,6 @@ export const CommentView = ({ comment, lastComment }) => { className="d-flex align-items-center" type="button" onClick={handleToggleLike} - disabled={!token} > {commentLikes.includes(userId) ? ( @@ -118,6 +125,11 @@ export const CommentView = ({ comment, lastComment }) => { )} + } + /> {commentLikes.length} )} diff --git a/src/features/questions/questions-list/question-actions/FavoritePopover.jsx b/src/features/questions/questions-list/question-actions/FavoritePopover.jsx index 9f0a44f..1d6bf08 100644 --- a/src/features/questions/questions-list/question-actions/FavoritePopover.jsx +++ b/src/features/questions/questions-list/question-actions/FavoritePopover.jsx @@ -6,9 +6,15 @@ import FavoritePopoverContent from './FavoritePopoverContent'; export const FavoritePopover = ({ children }) => { const { token } = useAuth(); + const text = 'что бы иметь возможность сохранять вопросы'; + if (!token) { return ( - + } + > {children} ); diff --git a/src/features/questions/questions-list/question-actions/FavoritePopoverContent.jsx b/src/features/questions/questions-list/question-actions/FavoritePopoverContent.jsx index 312ec88..04f470d 100644 --- a/src/features/questions/questions-list/question-actions/FavoritePopoverContent.jsx +++ b/src/features/questions/questions-list/question-actions/FavoritePopoverContent.jsx @@ -2,13 +2,14 @@ import React from 'react'; import { Link } from 'react-router-dom'; import { useAuth } from 'common/context/Auth/useAuth'; import styled from 'styled-components'; +import PropTypes from 'prop-types'; const StyledPopoverBlock = styled.div` width: 250px; text-align: center; `; -const FavoritePopoverContent = () => { +const FavoritePopoverContent = ({ text }) => { const { executeLoggingInProcess } = useAuth(); return ( @@ -16,9 +17,13 @@ const FavoritePopoverContent = () => { Авторизуйся, {' '} - чтобы иметь возможность сохранять вопросы + {text} ); }; export default FavoritePopoverContent; + +FavoritePopoverContent.propTypes = { + text: PropTypes.node.isRequired, +}; From f0c94031af9cb40c8ebede1ca67d8e69aaac6dba Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Feb 2023 15:30:57 +0300 Subject: [PATCH 2/5] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=80=D0=B0=D1=81=D0=BF=D0=BE=D0=BB=D0=BE=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D0=B8=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=B1=D0=B0=D0=B3=20=D1=81=20=D0=BF=D0=BE=D0=B2?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D1=8B=D0=BC=20=D0=BE=D1=82=D0=BA=D1=80?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=BF=D0=BE=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/comments/CommentView.jsx | 29 ++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/features/comments/CommentView.jsx b/src/features/comments/CommentView.jsx index 5755add..5c11d00 100644 --- a/src/features/comments/CommentView.jsx +++ b/src/features/comments/CommentView.jsx @@ -68,6 +68,15 @@ const StyledCommentActions = styled.div` display: flex; `; +const StyledPopoverBlock = styled.div` + position: relative; +`; + +const StyledPopoverChildren = styled.div` + position: absolute; + right: 47px; +`; + export const CommentView = ({ comment, lastComment }) => { const Wrapper = lastComment ? StyledWrapper : React.Fragment; @@ -95,6 +104,10 @@ export const CommentView = ({ comment, lastComment }) => { } else setOpen(!open); }; + const handleOpenPopover = () => { + setOpen(!open); + }; + return (
@@ -125,12 +138,18 @@ export const CommentView = ({ comment, lastComment }) => { )} - } - /> {commentLikes.length} + + + } + /> + + )} From 9a34405bea2ab9844f85b35034b10559a6446b58 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Feb 2023 15:45:29 +0300 Subject: [PATCH 3/5] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83=20=D0=B2=20=D1=82?= =?UTF-8?q?=D0=B5=D0=BA=D1=81=D1=82=D0=B5=20=D0=BF=D0=BE=D0=BF=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/comments/CommentView.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/comments/CommentView.jsx b/src/features/comments/CommentView.jsx index 5c11d00..ca41666 100644 --- a/src/features/comments/CommentView.jsx +++ b/src/features/comments/CommentView.jsx @@ -82,7 +82,7 @@ export const CommentView = ({ comment, lastComment }) => { const [open, setOpen] = useState(false); - const text = 'что бы иметь возможность лайкать комментарии'; + const text = 'чтобы иметь возможность лайкать комментарии'; const dispatch = useDispatch(); const { token } = useAuth(); From 9a864e926efe2d2fdce9c93ab788fcbcdbcfa4b6 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Feb 2023 16:19:53 +0300 Subject: [PATCH 4/5] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D0=BB=20?= =?UTF-8?q?=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD?= =?UTF-8?q?=D0=B3=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FavoritePopoverContent.jsx | 0 src/features/comments/CommentView.jsx | 18 ++++++++++-------- .../question-actions/FavoritePopover.jsx | 6 ++---- 3 files changed, 12 insertions(+), 12 deletions(-) rename src/{features/questions/questions-list/question-actions => components}/FavoritePopoverContent.jsx (100%) diff --git a/src/features/questions/questions-list/question-actions/FavoritePopoverContent.jsx b/src/components/FavoritePopoverContent.jsx similarity index 100% rename from src/features/questions/questions-list/question-actions/FavoritePopoverContent.jsx rename to src/components/FavoritePopoverContent.jsx diff --git a/src/features/comments/CommentView.jsx b/src/features/comments/CommentView.jsx index ca41666..481d721 100644 --- a/src/features/comments/CommentView.jsx +++ b/src/features/comments/CommentView.jsx @@ -7,7 +7,7 @@ import dayjs from 'dayjs'; import { HeartFilled, HeartOutlined } from '@ant-design/icons'; import { useDispatch, useSelector } from 'react-redux'; import { selectProfile } from 'features/profile/profileSlice'; -import FavoritePopoverContent from 'features/questions/questions-list/question-actions/FavoritePopoverContent'; +import FavoritePopoverContent from 'components/FavoritePopoverContent'; import { Popover } from 'antd'; import { CommentsActions } from './comment-actions/CommentsActions'; import { likeCommentById, unlikeCommentById } from './commentsSlice'; @@ -80,9 +80,7 @@ const StyledPopoverChildren = styled.div` export const CommentView = ({ comment, lastComment }) => { const Wrapper = lastComment ? StyledWrapper : React.Fragment; - const [open, setOpen] = useState(false); - - const text = 'чтобы иметь возможность лайкать комментарии'; + const [isAuthorizeEnable, setIsAuthorizeEnable] = useState(false); const dispatch = useDispatch(); const { token } = useAuth(); @@ -101,11 +99,13 @@ export const CommentView = ({ comment, lastComment }) => { } else { dispatch(unlikeCommentById({ commentId, userId })); } - } else setOpen(!open); + } else { + setIsAuthorizeEnable(true); + } }; const handleOpenPopover = () => { - setOpen(!open); + setIsAuthorizeEnable(!isAuthorizeEnable); }; return ( @@ -143,10 +143,12 @@ export const CommentView = ({ comment, lastComment }) => { } + content={ + + } /> diff --git a/src/features/questions/questions-list/question-actions/FavoritePopover.jsx b/src/features/questions/questions-list/question-actions/FavoritePopover.jsx index 1d6bf08..a9229d9 100644 --- a/src/features/questions/questions-list/question-actions/FavoritePopover.jsx +++ b/src/features/questions/questions-list/question-actions/FavoritePopover.jsx @@ -1,19 +1,17 @@ import { Popover } from 'antd'; import { useAuth } from 'common/context/Auth/useAuth'; import PropTypes from 'prop-types'; -import FavoritePopoverContent from './FavoritePopoverContent'; +import FavoritePopoverContent from 'components/FavoritePopoverContent'; export const FavoritePopover = ({ children }) => { const { token } = useAuth(); - const text = 'что бы иметь возможность сохранять вопросы'; - if (!token) { return ( } + content={} > {children} From c173ef8d3ecdd2e5dacad495012b6dd8a6f10fa2 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Feb 2023 16:27:18 +0300 Subject: [PATCH 5/5] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0=D0=BB=20=D1=81=D1=82=D0=B5=D0=B9=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/comments/CommentView.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/features/comments/CommentView.jsx b/src/features/comments/CommentView.jsx index 481d721..b8a86f2 100644 --- a/src/features/comments/CommentView.jsx +++ b/src/features/comments/CommentView.jsx @@ -80,7 +80,7 @@ const StyledPopoverChildren = styled.div` export const CommentView = ({ comment, lastComment }) => { const Wrapper = lastComment ? StyledWrapper : React.Fragment; - const [isAuthorizeEnable, setIsAuthorizeEnable] = useState(false); + const [isAuthorizePopoverEnable, setIsAuthorizePopoverEnable] = useState(false); const dispatch = useDispatch(); const { token } = useAuth(); @@ -100,12 +100,12 @@ export const CommentView = ({ comment, lastComment }) => { dispatch(unlikeCommentById({ commentId, userId })); } } else { - setIsAuthorizeEnable(true); + setIsAuthorizePopoverEnable(true); } }; const handleOpenPopover = () => { - setIsAuthorizeEnable(!isAuthorizeEnable); + setIsAuthorizePopoverEnable(!isAuthorizePopoverEnable); }; return ( @@ -143,7 +143,7 @@ export const CommentView = ({ comment, lastComment }) => {