// @flow import { lazyImport } from 'util/lazyImport'; import { formatLbryUrlForWeb } from 'util/url'; import { Menu, MenuList, MenuButton, MenuItem } from '@reach/menu-button'; import { NavLink } from 'react-router-dom'; import { PAGE_VIEW_QUERY, DISCUSSION_PAGE } from 'page/channel/view'; import { parseURI } from 'util/lbryURI'; import { RULE } from 'constants/notifications'; import { useHistory } from 'react-router'; import * as ICONS from 'constants/icons'; import * as PAGES from 'constants/pages'; import Button from 'component/button'; import ChannelThumbnail from 'component/channelThumbnail'; import classnames from 'classnames'; import DateTime from 'component/dateTime'; import FileThumbnail from 'component/fileThumbnail'; import Icon from 'component/common/icon'; import NotificationContentChannelMenu from 'component/notificationContentChannelMenu'; import React from 'react'; import UriIndicator from 'component/uriIndicator'; import { generateNotificationTitle } from './helpers/title'; import { generateNotificationText } from './helpers/text'; import { LINKED_COMMENT_QUERY_PARAM } from 'constants/comment'; const CommentCreate = lazyImport(() => import('component/commentCreate' /* webpackChunkName: "comments" */)); const CommentReactions = lazyImport(() => import('component/commentReactions' /* webpackChunkName: "comments" */)); const CommentsReplies = lazyImport(() => import('component/commentsReplies' /* webpackChunkName: "comments" */)); type Props = { menuButton: boolean, notification: WebNotification, deleteNotification: () => void, readNotification: () => void, }; export default function Notification(props: Props) { const { menuButton = false, notification, readNotification, deleteNotification } = props; const { notification_rule, notification_parameters, is_read } = notification; const { push } = useHistory(); const [isReplying, setReplying] = React.useState(false); const [quickReply, setQuickReply] = React.useState(); const isCommentNotification = notification_rule === RULE.COMMENT || notification_rule === RULE.COMMENT_REPLY || notification_rule === RULE.CREATOR_COMMENT; const notificationTarget = getNotificationTarget(); const creatorIcon = (channelUrl, channelThumbnail) => ( ); let channelUrl; let icon; switch (notification_rule) { case RULE.CREATOR_SUBSCRIBER: icon = ; break; case RULE.COMMENT: case RULE.CREATOR_COMMENT: channelUrl = notification_parameters.dynamic.comment_author; icon = creatorIcon(channelUrl, notification_parameters?.dynamic?.comment_author_thumbnail); break; case RULE.COMMENT_REPLY: channelUrl = notification_parameters.dynamic.reply_author; icon = creatorIcon(channelUrl, notification_parameters?.dynamic?.comment_author_thumbnail); break; case RULE.NEW_CONTENT: channelUrl = notification_parameters.dynamic.channel_url; icon = creatorIcon(channelUrl, notification_parameters?.dynamic?.channel_thumbnail); break; case RULE.NEW_LIVESTREAM: channelUrl = notification_parameters.dynamic.channel_url; icon = creatorIcon(channelUrl, notification_parameters?.dynamic?.channel_thumbnail); break; case RULE.WEEKLY_WATCH_REMINDER: case RULE.DAILY_WATCH_AVAILABLE: case RULE.DAILY_WATCH_REMIND: case RULE.MISSED_OUT: case RULE.REWARDS_APPROVAL_PROMPT: icon = ; break; case RULE.FIAT_TIP: icon = ; break; default: icon = ; } let notificationLink = formatLbryUrlForWeb(notificationTarget); let urlParams = new URLSearchParams(); if (isCommentNotification && notification_parameters.dynamic.hash) { urlParams.append(LINKED_COMMENT_QUERY_PARAM, notification_parameters.dynamic.hash); } let channelName; if (channelUrl) { try { ({ claimName: channelName } = parseURI(channelUrl)); } catch (e) {} } try { const { isChannel } = parseURI(notificationTarget); if (isChannel) urlParams.append(PAGE_VIEW_QUERY, DISCUSSION_PAGE); } catch (e) {} notificationLink += `?${urlParams.toString()}`; const navLinkProps = { to: notificationLink, onClick: (e) => e.stopPropagation() }; function getNotificationTarget() { switch (notification_rule) { case RULE.WEEKLY_WATCH_REMINDER: case RULE.DAILY_WATCH_AVAILABLE: case RULE.DAILY_WATCH_REMIND: return `/$/${PAGES.CHANNELS_FOLLOWING}`; case RULE.MISSED_OUT: case RULE.REWARDS_APPROVAL_PROMPT: return `/$/${PAGES.REWARDS_VERIFY}?redirect=/$/${PAGES.REWARDS}`; default: return notification_parameters.device.target; } } function handleNotificationClick() { if (!is_read) readNotification(); if (menuButton && notificationLink) push(notificationLink); } const Wrapper = menuButton ? (props: { children: any }) => ( {props.children} ) : notificationLink ? (props: { children: any }) => ( {props.children} ) : (props: { children: any }) => ( {props.children} ); return (
{icon}
{generateNotificationTitle(notification_rule, notification_parameters, channelName)}
{generateNotificationText(notification_rule, notification_parameters)}
{notification_rule === RULE.NEW_CONTENT && ( )} {notification_rule === RULE.NEW_LIVESTREAM && ( )}
{!is_read && (
{ e.preventDefault(); e.stopPropagation(); }} > deleteNotification()}> {__('Delete')} {notification_rule === RULE.NEW_CONTENT && channelUrl ? ( ) : null}
{isCommentNotification && (
{isReplying && ( setReplying(false)} onCancelReplying={() => setReplying(false)} setQuickReply={setQuickReply} supportDisabled shouldFetchComment /> )} {quickReply && ( )}
)}
); }