2021-03-03 19:50:16 +01:00
|
|
|
// @flow
|
2021-03-12 14:48:42 +01:00
|
|
|
import { URL, SHARE_DOMAIN_URL } from 'config';
|
2021-03-03 19:50:16 +01:00
|
|
|
import * as ICONS from 'constants/icons';
|
2021-03-31 10:01:49 +02:00
|
|
|
import * as PAGES from 'constants/pages';
|
2021-03-03 19:50:16 +01:00
|
|
|
import React from 'react';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { Menu, MenuButton, MenuList, MenuItem } from '@reach/menu-button';
|
|
|
|
import Icon from 'component/common/icon';
|
2021-03-12 14:48:42 +01:00
|
|
|
import { generateShareUrl } from 'util/url';
|
2021-03-31 10:01:49 +02:00
|
|
|
import { useHistory } from 'react-router';
|
2021-03-12 14:48:42 +01:00
|
|
|
|
|
|
|
const SHARE_DOMAIN = SHARE_DOMAIN_URL || URL;
|
2021-03-03 19:50:16 +01:00
|
|
|
|
|
|
|
type Props = {
|
2021-03-12 14:48:42 +01:00
|
|
|
uri: string,
|
2021-03-03 19:50:16 +01:00
|
|
|
claim: ?Claim,
|
|
|
|
inline?: boolean,
|
|
|
|
claimIsMine: boolean,
|
|
|
|
channelIsMuted: boolean,
|
|
|
|
channelIsBlocked: boolean,
|
|
|
|
doToggleMuteChannel: (string) => void,
|
|
|
|
doCommentModBlock: (string) => void,
|
|
|
|
doCommentModUnBlock: (string) => void,
|
2021-05-15 07:53:56 +02:00
|
|
|
channelIsMine: boolean,
|
|
|
|
isRepost: boolean,
|
2021-03-03 19:50:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function ClaimMenuList(props: Props) {
|
|
|
|
const {
|
2021-03-12 14:48:42 +01:00
|
|
|
uri,
|
2021-03-03 19:50:16 +01:00
|
|
|
claim,
|
|
|
|
inline = false,
|
|
|
|
claimIsMine,
|
|
|
|
doToggleMuteChannel,
|
|
|
|
channelIsMuted,
|
|
|
|
channelIsBlocked,
|
|
|
|
doCommentModBlock,
|
|
|
|
doCommentModUnBlock,
|
|
|
|
} = props;
|
2021-03-31 10:01:49 +02:00
|
|
|
|
|
|
|
const { push } = useHistory();
|
|
|
|
|
2021-03-03 19:50:16 +01:00
|
|
|
const channelUri =
|
|
|
|
claim &&
|
|
|
|
(claim.value_type === 'channel'
|
|
|
|
? claim.permanent_url
|
|
|
|
: claim.signing_channel && claim.signing_channel.permanent_url);
|
|
|
|
|
2021-03-12 14:48:42 +01:00
|
|
|
const shareUrl: string = generateShareUrl(SHARE_DOMAIN, uri);
|
|
|
|
|
2021-03-04 22:01:14 +01:00
|
|
|
if (!channelUri || !claim) {
|
2021-03-03 19:50:16 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleToggleMute() {
|
|
|
|
doToggleMuteChannel(channelUri);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleToggleBlock() {
|
|
|
|
if (channelIsBlocked) {
|
|
|
|
doCommentModUnBlock(channelUri);
|
|
|
|
} else {
|
|
|
|
doCommentModBlock(channelUri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-04 22:01:14 +01:00
|
|
|
function handleCopyLink() {
|
2021-03-12 14:48:42 +01:00
|
|
|
navigator.clipboard.writeText(shareUrl);
|
2021-03-04 22:01:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function handleReportContent() {
|
2021-03-31 10:01:49 +02:00
|
|
|
push(`/$/${PAGES.REPORT_CONTENT}?claimId=${claim.claim_id}`);
|
2021-03-04 22:01:14 +01:00
|
|
|
}
|
|
|
|
|
2021-03-03 19:50:16 +01:00
|
|
|
return (
|
|
|
|
<Menu>
|
|
|
|
<MenuButton
|
|
|
|
className={classnames('menu__button', { 'claim__menu-button': !inline, 'claim__menu-button--inline': inline })}
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Icon size={20} icon={ICONS.MORE_VERTICAL} />
|
|
|
|
</MenuButton>
|
|
|
|
<MenuList className="menu__list">
|
|
|
|
{!claimIsMine && (
|
|
|
|
<>
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={handleToggleBlock}>
|
|
|
|
<div className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.BLOCK} />
|
|
|
|
{channelIsBlocked ? __('Unblock Channel') : __('Block Channel')}
|
|
|
|
</div>
|
|
|
|
</MenuItem>
|
|
|
|
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={handleToggleMute}>
|
|
|
|
<div className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.MUTE} />
|
|
|
|
{channelIsMuted ? __('Unmute Channel') : __('Mute Channel')}
|
|
|
|
</div>
|
|
|
|
</MenuItem>
|
2021-03-04 22:01:14 +01:00
|
|
|
|
2021-03-08 18:37:45 +01:00
|
|
|
<hr className="menu__separator" />
|
2021-03-03 19:50:16 +01:00
|
|
|
</>
|
|
|
|
)}
|
2021-03-04 22:01:14 +01:00
|
|
|
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={handleCopyLink}>
|
|
|
|
<div className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.SHARE} />
|
|
|
|
{__('Copy Link')}
|
|
|
|
</div>
|
|
|
|
</MenuItem>
|
|
|
|
|
|
|
|
{!claimIsMine && (
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={handleReportContent}>
|
|
|
|
<div className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.REPORT} />
|
|
|
|
{__('Report Content')}
|
|
|
|
</div>
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
2021-03-03 19:50:16 +01:00
|
|
|
</MenuList>
|
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ClaimMenuList;
|