Allow to react/reply to comments from notifications

This commit is contained in:
saltrafael 2021-07-27 14:01:52 -03:00
parent 08cca491fe
commit ec6a2c315b
No known key found for this signature in database
GPG key ID: 9C7F1DC0B0F54515
2 changed files with 99 additions and 47 deletions

View file

@ -9,6 +9,7 @@ import DateTime from 'component/dateTime';
import Button from 'component/button'; import Button from 'component/button';
import ChannelThumbnail from 'component/channelThumbnail'; import ChannelThumbnail from 'component/channelThumbnail';
import { formatLbryUrlForWeb } from 'util/url'; import { formatLbryUrlForWeb } from 'util/url';
import { useHistory } from 'react-router';
import { parseURI } from 'lbry-redux'; import { parseURI } from 'lbry-redux';
import { PAGE_VIEW_QUERY, DISCUSSION_PAGE } from 'page/channel/view'; import { PAGE_VIEW_QUERY, DISCUSSION_PAGE } from 'page/channel/view';
import FileThumbnail from 'component/fileThumbnail'; import FileThumbnail from 'component/fileThumbnail';
@ -17,6 +18,8 @@ import NotificationContentChannelMenu from 'component/notificationContentChannel
import LbcMessage from 'component/common/lbc-message'; import LbcMessage from 'component/common/lbc-message';
import { NavLink } from 'react-router-dom'; import { NavLink } from 'react-router-dom';
import UriIndicator from 'component/uriIndicator'; import UriIndicator from 'component/uriIndicator';
import CommentReactions from 'component/commentReactions';
// import CommentCreate from 'component/commentCreate';
type Props = { type Props = {
notification: WebNotification, notification: WebNotification,
@ -28,7 +31,9 @@ type Props = {
export default function Notification(props: Props) { export default function Notification(props: Props) {
const { notification, menuButton = false, doReadNotifications, doDeleteNotification } = props; const { notification, menuButton = false, doReadNotifications, doDeleteNotification } = props;
const { push } = useHistory();
const { notification_rule, notification_parameters, is_read, id } = notification; const { notification_rule, notification_parameters, is_read, id } = notification;
const [isReplying, setReplying] = React.useState(false);
const isCommentNotification = const isCommentNotification =
notification_rule === RULE.COMMENT || notification_rule === RULE.COMMENT ||
notification_rule === RULE.COMMENT_REPLY || notification_rule === RULE.COMMENT_REPLY ||
@ -127,6 +132,10 @@ export default function Notification(props: Props) {
if (!is_read) { if (!is_read) {
doReadNotifications([id]); doReadNotifications([id]);
} }
if (notificationLink) {
push(notificationLink);
}
} }
function handleReadNotification(e) { function handleReadNotification(e) {
@ -134,6 +143,10 @@ export default function Notification(props: Props) {
doReadNotifications([id]); doReadNotifications([id]);
} }
function handleCommentReply() {
setReplying(!isReplying);
}
const Wrapper = menuButton const Wrapper = menuButton
? (props: { children: any }) => ( ? (props: { children: any }) => (
<MenuItem className="menu__link--notification" onSelect={handleNotificationClick}> <MenuItem className="menu__link--notification" onSelect={handleNotificationClick}>
@ -156,18 +169,20 @@ export default function Notification(props: Props) {
); );
return ( return (
<NavLink {...navLinkProps}>
<Wrapper> <Wrapper>
<div <div
className={classnames('notification__wrapper', { className={classnames('notification__wrapper', {
'notification__wrapper--unread': !is_read, 'notification__wrapper--unread': !is_read,
})} })}
> >
<NavLink {...navLinkProps}>
<div className="notification__icon">{icon}</div> <div className="notification__icon">{icon}</div>
</NavLink>
<div className="notification__content-wrapper"> <div className="notification__content-wrapper">
<div className="notification__content"> <div className="notification__content">
<div className="notification__text-wrapper"> <div className="notification__text-wrapper">
<NavLink {...navLinkProps}>
{!isCommentNotification && ( {!isCommentNotification && (
<div className="notification__title">{title}</div> <div className="notification__title">{title}</div>
)} )}
@ -189,6 +204,33 @@ export default function Notification(props: Props) {
</div> </div>
</> </>
)} )}
</NavLink>
{isCommentNotification && (
<div className="notification__reactions">
<Button
label={__('Reply')}
className="comment__action"
onClick={handleCommentReply}
icon={ICONS.REPLY}
/>
<CommentReactions uri={notificationTarget} commentId={notification_parameters.dynamic.hash} />
{/* figure out a better flow for this */}
{/* isReplying && (
<CommentCreate
isReply
uri={notificationTarget}
parentId={notification_parameters.dynamic.hash}
onDoneReplying={() => {
setReplying(false);
}}
onCancelReplying={() => {
setReplying(false);
}}
/>
) */}
</div>
)}
</div> </div>
{notification_rule === RULE.NEW_CONTENT && ( {notification_rule === RULE.NEW_CONTENT && (
@ -212,9 +254,7 @@ export default function Notification(props: Props) {
<div className="notification__menu"> <div className="notification__menu">
<Menu> <Menu>
<MenuButton <MenuButton onClick={(e) => {
className={'menu__button notification__menu-button'}
onClick={(e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
}}> }}>
@ -233,6 +273,5 @@ export default function Notification(props: Props) {
</div> </div>
</div> </div>
</Wrapper> </Wrapper>
</NavLink>
); );
} }

View file

@ -162,6 +162,19 @@ $contentMaxWidth: 60rem;
} }
} }
.notification__reactions {
display: flex;
margin-top: var(--spacing-s);
> *:not(:last-of-type) {
margin-right: var(--spacing-m);
}
.button__label {
margin-left: var(--spacing-xs);
}
}
.notification__bubble { .notification__bubble {
height: 1.5rem; height: 1.5rem;
width: 1.5rem; width: 1.5rem;