@@ -2,11 +2,13 @@ import { Viewer } from '@toast-ui/react-editor';
22import { useAuth } from 'common/context/Auth/useAuth' ;
33import PropTypes from 'prop-types' ;
44import styled from 'styled-components' ;
5- import React from 'react' ;
5+ import React , { useState } from 'react' ;
66import dayjs from 'dayjs' ;
77import { HeartFilled , HeartOutlined } from '@ant-design/icons' ;
88import { useDispatch , useSelector } from 'react-redux' ;
99import { selectProfile } from 'features/profile/profileSlice' ;
10+ import FavoritePopoverContent from 'components/FavoritePopoverContent' ;
11+ import { Popover } from 'antd' ;
1012import { CommentsActions } from './comment-actions/CommentsActions' ;
1113import { likeCommentById , unlikeCommentById } from './commentsSlice' ;
1214
@@ -66,9 +68,20 @@ const StyledCommentActions = styled.div`
6668 display: flex;
6769` ;
6870
71+ const StyledPopoverBlock = styled . div `
72+ position: relative;
73+ ` ;
74+
75+ const StyledPopoverChildren = styled . div `
76+ position: absolute;
77+ right: 47px;
78+ ` ;
79+
6980export const CommentView = ( { comment, lastComment } ) => {
7081 const Wrapper = lastComment ? StyledWrapper : React . Fragment ;
7182
83+ const [ isAuthorizePopoverEnable , setIsAuthorizePopoverEnable ] = useState ( false ) ;
84+
7285 const dispatch = useDispatch ( ) ;
7386 const { token } = useAuth ( ) ;
7487
@@ -80,13 +93,21 @@ export const CommentView = ({ comment, lastComment }) => {
8093 const userId = profile . _id ;
8194
8295 const handleToggleLike = ( ) => {
83- if ( ! commentLikes . includes ( userId ) ) {
84- dispatch ( likeCommentById ( { commentId, userId } ) ) ;
96+ if ( token ) {
97+ if ( ! commentLikes . includes ( userId ) ) {
98+ dispatch ( likeCommentById ( { commentId, userId } ) ) ;
99+ } else {
100+ dispatch ( unlikeCommentById ( { commentId, userId } ) ) ;
101+ }
85102 } else {
86- dispatch ( unlikeCommentById ( { commentId , userId } ) ) ;
103+ setIsAuthorizePopoverEnable ( true ) ;
87104 }
88105 } ;
89106
107+ const handleOpenPopover = ( ) => {
108+ setIsAuthorizePopoverEnable ( ! isAuthorizePopoverEnable ) ;
109+ } ;
110+
90111 return (
91112 < Wrapper >
92113 < div className = "row align-items mb-4 g-1" >
@@ -110,7 +131,6 @@ export const CommentView = ({ comment, lastComment }) => {
110131 className = "d-flex align-items-center"
111132 type = "button"
112133 onClick = { handleToggleLike }
113- disabled = { ! token }
114134 >
115135 { commentLikes . includes ( userId ) ? (
116136 < HeartFilled style = { { color : '#FF4646' } } />
@@ -119,6 +139,19 @@ export const CommentView = ({ comment, lastComment }) => {
119139 ) }
120140 </ button >
121141 < span > { commentLikes . length } </ span >
142+ < StyledPopoverBlock >
143+ < StyledPopoverChildren >
144+ < Popover
145+ onOpenChange = { handleOpenPopover }
146+ open = { isAuthorizePopoverEnable }
147+ trigger = "click"
148+ placement = "bottomLeft"
149+ content = {
150+ < FavoritePopoverContent text = "чтобы иметь возможность лайкать комментарии" />
151+ }
152+ />
153+ </ StyledPopoverChildren >
154+ </ StyledPopoverBlock >
122155 </ StyledCommentLikes >
123156 ) }
124157 </ StyledCommentActions >
0 commit comments