// @flow import { URL, SHARE_DOMAIN_URL } from 'config'; import * as ICONS from 'constants/icons'; import * as PAGES from 'constants/pages'; import * as MODALS from 'constants/modal_types'; import React from 'react'; import classnames from 'classnames'; import { Menu, MenuButton, MenuList, MenuItem } from '@reach/menu-button'; import Icon from 'component/common/icon'; import { generateShareUrl } from 'util/url'; import { useHistory } from 'react-router'; import { COLLECTIONS_CONSTS } from 'lbry-redux'; const SHARE_DOMAIN = SHARE_DOMAIN_URL || URL; type Props = { uri: string, claim: ?Claim, inline?: boolean, claimIsMine: boolean, channelIsMuted: boolean, channelIsBlocked: boolean, doToggleMuteChannel: (string) => void, doCommentModBlock: (string) => void, doCommentModUnBlock: (string) => void, channelIsMine: boolean, isRepost: boolean, doCollectionEdit: (string, any) => void, hasClaimInWatchLater: boolean, doOpenModal: (string, {}) => void, claimInCollection: boolean, collectionName?: string, collectionId: string, isMyCollection: boolean, doToast: ({ message: string }) => void, hasExperimentalUi: boolean, }; function ClaimMenuList(props: Props) { const { uri, claim, inline = false, claimIsMine, doToggleMuteChannel, channelIsMuted, channelIsBlocked, doCommentModBlock, doCommentModUnBlock, doCollectionEdit, hasClaimInWatchLater, doOpenModal, collectionId, collectionName, isMyCollection, doToast, hasExperimentalUi, } = props; const { push } = useHistory(); if (!claim) { return null; } const channelUri = claim ? claim.value_type === 'channel' ? claim.permanent_url : (claim.signing_channel && claim.signing_channel.permanent_url) || '' : ''; const shareUrl: string = generateShareUrl(SHARE_DOMAIN, uri); const isCollectionClaim = claim && claim.value_type === 'collection'; // $FlowFixMe const isPlayable = claim && !claim.repost_url && // $FlowFixMe claim.value.stream_type && // $FlowFixMe (claim.value.stream_type === 'audio' || claim.value.stream_type === 'video'); function handleToggleMute() { doToggleMuteChannel(channelUri); } function handleToggleBlock() { if (channelIsBlocked) { doCommentModUnBlock(channelUri); } else { doCommentModBlock(channelUri); } } function handleCopyLink() { navigator.clipboard.writeText(shareUrl); } function handleReportContent() { push(`/$/${PAGES.REPORT_CONTENT}?claimId=${claim.claim_id}`); } return ( { e.stopPropagation(); e.preventDefault(); }} > {hasExperimentalUi && ( <> {/* WATCH LATER */} {isPlayable && !collectionId && ( <> { doToast({ message: __('Item %action% Watch Later', { action: hasClaimInWatchLater ? __('removed from') : __('added to'), }), }); doCollectionEdit(COLLECTIONS_CONSTS.WATCH_LATER_ID, { claims: [claim], remove: hasClaimInWatchLater, type: 'playlist', }); }} >
{hasClaimInWatchLater ? __('In Watch Later') : __('Watch Later')}
)} {/* COLLECTION OPERATIONS */} {collectionId && collectionName && isCollectionClaim && ( <> push(`/$/${PAGES.LIST}/${collectionId}`)}>
{__('View List')}
doOpenModal(MODALS.COLLECTION_DELETE, { collectionId })} >
{__('Delete List')}
)} {/* CURRENTLY ONLY SUPPORT PLAYLISTS FOR PLAYABLE; LATER DIFFERENT TYPES */} {isPlayable && ( doOpenModal(MODALS.COLLECTION_ADD, { uri, type: 'playlist' })} >
{__('Add to Lists')}
)} )}
{channelUri && !claimIsMine && !isMyCollection && ( <>
{channelIsBlocked ? __('Unblock Channel') : __('Block Channel')}
{channelIsMuted ? __('Unmute Channel') : __('Mute Channel')}

)}
{__('Copy Link')}
{!claimIsMine && !isMyCollection && (
{__('Report Content')}
)}
); } export default ClaimMenuList;