// @flow import { NOTIFICATION_CREATOR_SUBSCRIBER, NOTIFICATION_COMMENT } from 'constants/notifications'; import * as ICONS from 'constants/icons'; import React from 'react'; import classnames from 'classnames'; import Icon from 'component/common/icon'; import DateTime from 'component/dateTime'; import Button from 'component/button'; import ChannelThumbnail from 'component/channelThumbnail'; import { MenuItem } from '@reach/menu-button'; import { formatLbryUrlForWeb } from 'util/url'; import { useHistory } from 'react-router'; import { parseURI } from 'lbry-redux'; import { PAGE_VIEW_QUERY, DISCUSSION_PAGE } from 'page/channel/view'; type Props = { notification: WebNotification, menuButton: boolean, children: any, doSeeNotifications: ([number]) => void, }; export default function Notification(props: Props) { const { notification, menuButton = false, doSeeNotifications } = props; const { push } = useHistory(); const { notification_rule, notification_parameters, is_seen, id } = notification; const notificationTarget = notification && notification_parameters.device.target; const commentText = notification_rule === NOTIFICATION_COMMENT && notification_parameters.dynamic.comment; let notificationLink = formatLbryUrlForWeb(notificationTarget); let urlParams = new URLSearchParams(); if (notification_rule === NOTIFICATION_COMMENT && notification_parameters.dynamic.hash) { urlParams.append('lc', notification_parameters.dynamic.hash); } try { const { isChannel } = parseURI(notificationTarget); if (isChannel) { urlParams.append(PAGE_VIEW_QUERY, DISCUSSION_PAGE); } } catch (e) {} notificationLink += `?${urlParams.toString()}`; let icon; switch (notification_rule) { case NOTIFICATION_CREATOR_SUBSCRIBER: icon = ; break; case NOTIFICATION_COMMENT: icon = ; break; default: icon = ; } function handleNotificationClick() { if (!is_seen) { doSeeNotifications([id]); } if (notificationLink) { push(notificationLink); } } function handleSeeNotification(e) { e.stopPropagation(); doSeeNotifications([id]); } const Wrapper = menuButton ? (props: { children: any }) => ( {props.children} ) : notificationLink ? (props: { children: any }) => ( {props.children} ) : (props: { children: any }) => ( {props.children} ); return (
{icon}
{notification_rule !== NOTIFICATION_COMMENT && (
{notification_parameters.device.title}
)} {notification_rule === NOTIFICATION_COMMENT && commentText ? ( <>
{notification_parameters.device.title}
{commentText}
) : ( <>
{notification_parameters.device.text}
)}
{!is_seen &&
); }